In music, a fugue () is a type of contrapuntal composition or technique of composition for a fixed number of parts, normally referred to as "voices". In the Middle Ages, the term was widely used to denote any works in canonic style; by the Renaissance, it had come to denote specifically imitative works. Since the 17th century, the term fugue has described what is commonly regarded as the most fully developed procedure of imitative counterpoint. A fugue opens with one main theme, the subject, which then sounds successively in each voice in imitation; when each voice has entered, the exposition is complete; this is occasionally followed by a connecting passage, or episode, developed from previously heard material; further "entries" of the subject then are heard in related keys. Episodes (if applicable) and entries are usually alternated until the "final entry" of the subject, by which point the music has returned to the opening key, or tonic, which is often followed by closing material, the coda. In this sense, fugue is a style of composition, rather than fixed structure. Though there are certain established practices, in writing the exposition for example, composers approach the style with varying degrees of freedom and individuality.
The form evolved during the 17th century from several earlier types of contrapuntal compositions, such as imitative ricercars, capriccios, canzonas, and fantasias. Middle and late Baroque composers such as Dietrich Buxtehude (1637–1707) and Johann Pachelbel (1653–1706) contributed greatly to the development of the fugue, and the form reached ultimate maturity in the works of Johann Sebastian Bach (1685–1750). With the decline of sophisticated contrapuntal styles at the end of the baroque period, the fugue's popularity as a compositional style waned, eventually giving way to sonata form. Nevertheless, composers from the 1750s to the present day continue to write and study fugue for various purposes; they appear in the works of Mozart (e.g. Kyrie Eleison of the Requiem in D minor) and Beethoven (e.g. end of the Credo of the Missa Solemnis), and many composers such as Anton Reicha (1770–1836) and Dmitri Shostakovich (1906–1975) wrote cycles of fugues.
The English term fugue originates in the 16th century and is derived from either the French or Italian fuga, which in turn comes from Latin, also fuga, which is itself related to both fugere (‘to flee’) and fugare, (‘to chase’). The adjectival form is fugal. Variants include fughetta (literally, 'a small fugue') and fugato (a passage in fugal style within another work that is not a fugue).
A fugue begins with what is known as the exposition and is characteristically written according to certain predefined rules; in later portions the composer has somewhat more freedom, though a logical key structure is usually followed, and further "entries" of the subject will occur throughout the fugue, repeating the accompanying material at the same time. The various entries may or may not be separated by episodes.
What follows is a chart displaying a fairly typical fugal outline, and a detailed explanation of the processes involved in creating this structure, with examples.