From their first meeting in May 1853, Brahms and internationally famous violinist Joseph Joachim (1831-1907) became the best of friends. For several years the two collaborated on the study of composition, orchestration, and counterpoint, and Joachim's string quartet played through some of Brahms' chamber music. Brahms wrote many of his counterpoint exercises at the organ, creating Baroque-style compositions based on hymn melodies.
While in Düsseldorf in 1856, visiting Clara Schumann, Brahms composed the Prelude and Fugue on "O Traurigkeit, O Herzeleid" for organ in A minor, WoO. 7. Of the four known works that appeared at this time, only two were published by Brahms during his life: the Prelude and Fugue on "O Traurigkeit" and the Fugue in A flat minor, published in 1882 and 1864, respectively. The other two are Preludes and Fugues in A minor (dedicated to Clara Schumann) and G minor, printed together in 1927.
Brief organ interludes separate each phrase of the chorale during the "O Traurigkeit" Prelude, in which the highest and lowest voices are in 4/4 meter, while the central, accompanimental, voice moves in 12/8. The metric disparity is apparent in only a few spots, making it all the more effective. A continuous flow in the middle register creates a forward motion that stops, somewhat abruptly, on A major. Immediately returning to A minor, the Fugue subject is derived from the second, third and fourth notes of the "O Traurigkeit" tune and is used freely in each of its first three entrances in what is really a three-voice fugue, the pedal part of which never contains the subject. Brahms' abandonment of strict Baroque fugue practice is evident from the beginning as the second voice enters with an inversion of the subject, not the original form.