Just as there are forgeries and fakes in the visual arts, there are forgeries and fakes found throughout musical history. The primary difference is that paintings passed off as originals are usually exact reproductions of original works, whereas counterfeit musical works only sound like original works. It's also not that they aren't original either, it's just that they are not composed by the person who's name is attached as the composer. It is also typical that the only way that these are discovered to be fakes, or rather, hoaxes, is by the real composer or someone close to them coming forward and admitting it.
Most of the more well-known examples of compositional deception were perpetrated in the last 150 years or so. There are many 18th and 19th century instances of music being published under a well-known composer's name -- such as the Toy Symphony published under Haydn's name -- in order for the publisher to sell more product. These types of things have largely been proven to be spurious through painstaking research and analysis of manuscripts, frequently without any revelations as to the actual composer. (The authorship of the Toy Symphony is still debated; is it by Leopold Mozart or by the Austrian monk Edmund Angerer?)
Why do people write music and pass it off as someone else's? Some may do it to gain respect as a thorough musicologist. Some do it at the urging of a publisher in order to profit more easily. Fritz Kreisler did it because he wanted to expand his recital repertoire but didn't want printed programs to be dominated with his name. When Kreisler began his career around the turn of the 20th century, he toured primarily as a recitalist, performing many shorter pieces along with long works such as Beethoven sonatas. The small items he wrote and ascribed to Tartini, Porpora, Padre Martini, and Vivaldi are among his most remembered works now and are heard frequently as encores today. The Sicilienne and Rigaudon "in the style of Francoeur" -- the way the works are now known -- has become a particularly popular piece of Kreisler's hoaxing, as have La Précieuse "by Louis Couperin" and Praeludium and Allegro in the style of Pugnani. When Kreisler finally admitted publically in 1935 that he had written the pieces himself, many people -- including other famous musicians who hadn't suspected anything -- immediately derided his actions. Others, like Yehudi Menuhin and Efrem Zimbalist, supported him. Time has proven him right when he said "The name changes, the value remains."
Pink Martini - Kreisler: Praeludium & Allegro in the style of Pugnani
The other widely famous piece of 20th century musical fakery is the Albinoni Adagio, actually written by Albinoni biographer Remo Giazotto. Giazotto claimed to have found a bit of manuscript, that most likely went with Albinoni's Op. 4 set of trio sonatas, in the collections of the Saxon State Library, which had been rescued from destruction during World War II. He then wrote out the somewhat elegaic and sombre movement for organ and strings and published it in 1958 with Tomaso Albinoni's name on it. In 1990 the library confirmed that it could find no such fragment in its holdings, and since Giazotto's death in 1998, it has been generally accepted that the entire story was a fiction. That has not stopped lazy music publishers and recording producers from continuing to attribute the Adagio to Albinoni, thereby perpetuating the false authorship.
Several more -- but lesser known -- examples of works persist on albums and in sheet music arrangements under a famous composer's name but written by someone else. There's a Toccata ascribed to Girolamo Frescobaldi, but actually written by the cellist Gaspar Cassadó. There are many transcriptions of the Toccata for brass instruments or orchestra, still being published as originally by Frescobaldi even though Cassadó's deception was proved in 1978. It wasn't the only piece he wrote and credited to another: there's also his Allegro grazioso by Schubert.
Canadian Brass - Cassadó: Frescobaldi's Toccata
Another case is the Suite in A minor for guitar "by Sylvius Leopold Weiss," in truth by Manuel Ponce. Andrés Segovia (left) said that in 1929 he asked Ponce for a suite in the style of Bach as a joke on Fritz Kreisler for a recital they would perform together. Segovia supposedly was one of those musicians who knew about Kreisler's handiwork. Segovia thought using Weiss' name instead of Bach's would make the joke harder to discern. For those familiar with the modern guitar or with Baroque music, the suite is obviously a contemporary composition, using pseudo-Baroque techniques, more modern harmony, and being ideally suited to the instrument (a true Baroque piece would not be, and would have needed editing). In short, many people knew this was a pretense, but it wasn't formally pronounced as such until 1964. However, even after that time Segovia recorded and performed the suite or its movements citing Weiss as the composer rather than Ponce. And again, Ponce demonstrated his imitative skills in more than one work.
The brothers Henri and Marius Casadesus are credited with authorship of concertos they claimed were composed by Handel, C.P.E. Bach, and even Mozart. The latter, known as the Adelaide Concerto was so convincing that it was added to the third edition of the Köchel catalog. Its correct credit to Marius Casadesus was revealed in 1977 when Casadesus had to testify in a copyright dispute.
Of course, compositional misattribution has gone on as long as music has been written down and disseminated through copies or publication. In the catalogs of all the major composers up through the early Romantic era there are all kinds of works attributed to Bach, Haydn, Beethoven, and others, that they simply did not write. That's not to say that these were deliberate forgeries, but in some cases they may have been. Since the period performance movement began in the 1960s, it has become much harder to play such tricks. So much more is known about manuscript authentication and the stylistic details of many composers, not just the major ones, that it would be difficult to convince even the least suspicious musician. In the early 21st century, we hear more frequently about doubtful pieces finally being exactly attributed than we do about debunking of fraudulent ascriptions. However, who knows what undivulged secrets are still out there?