A veritable lesson in everything a late baroque or early classical composer might consider to be "bad music theory," Mozart's "A Musical Joke" or "Some Musical Fun" (K. 522) is an intentionally funny, intentionally awful bit of music. Scored for two French horns and a string quartet in the Divertimento subgenre of light-hearted chamber music, the overall piece has four movements: an Allegro, a Menuetto and Trio, Adagio cantabile, and a Presto in the form of a Sonata rondo.
Many parts of the piece are polytonal, meaning that it frequently sounds as if at least one instrument in the performance is out of tune, or just being played totally incorrectly. In several places, the horn players are given a "solo" which involves a single long trilled note played extremely loudly in a pitch which is offensively set against delicate music from the strings.
There is a great deal of repetition, taken to extremes which are apparently intended to be persistently annoying throughout the course of each movement, restating a simplistic theme. Mozart never overtly stated that he was parodying incompetent composers and inept performers, and on 14 June 1787, he included it in Verzeichnis aller meiner Werke, the catalogue of his works, alongside his serious compositions.
It is notable upon examining the musical score that in many instances, it is actually much more difficult to play the music "wrongly" as written, than to play it "correctly" contrary to the score. The entire piece has considerable technical and performative difficulty written into it, so the musicians must put quite a bit of effort into actually achieving the "mistakes" Mozart intended for the composition.
Mozart composed the last three movements of Ein Musikalischer Spaß during the month after his father died (28 May 1787); it was written simultaneously to the opera Don Giovanni and another famous Mozart Divertimento, Eine Kleine Nachtmusik. The first movement of Ein Musikalischer Spaß was written two or three years prior, and there are noted instances of it having been performed in public long before the other three movements were written. This is meaningful, because, while the first movement conveys a strong sense of mockery toward other composers, possibly directed at Mozart's pupils Sussmayer and Hummel, or his then-popular contemporaries, Gyrowetz and Duschek, the latter movements contain features which no composer of that time was using or would even consider using.
Polytonality, phrase asymmetry, and several other features which Mozart demonstrated as antithetical to the classical style, proved to be somewhat revolutionary concepts to introduce into western music, and in later years, Igor Stravinsky would adopt these techniques very noticeably in his Firebird ballet. Claude Debussy and several other early twentieth century composers also would eventually use the "humour" Mozart introduced, in their own completely serious works. What Mozart confronted as musical impossibilities, Stravinsky, Debussy, and others translated into a completely new set of musical genres.
As with most music of such advanced age, Ein Musikalischer Spaß is in the public domain now, and free sheet music and MIDI files of it can easily be obtained through the Mutopia Project.