In Leipzig, Mahler befriended Captain Carl von Weber (1849–1897), grandson of the composer, and agreed to prepare a performing version of Carl Maria von Weber's unfinished opera Die drei Pintos ("The Three Pintos"). Mahler transcribed and orchestrated the existing musical sketches, used parts of other Weber works, and added some composition of his own. The premiere at the Stadttheater, on 20 January 1888, was an important occasion at which several heads of various German opera houses were present. (The Russian composer Tchaikovsky attended the third performance on 29 January.) The work was well-received; its success did much to raise Mahler's public profile, and brought him financial rewards. Mahler's involvement with the Weber family was complicated by Mahler's alleged romantic attachment to Carl von Weber's wife Marion Mathilde (1857–1931) which, though intense on both sides – so it was rumoured by for example English composer Ethel Smyth) – ultimately came to nothing. In February and March 1888 Mahler sketched and completed his First Symphony, then in five movements. At around the same time Mahler discovered the German folk-poem collection Des Knaben Wunderhorn ("The Youth's Magic Horn"), which would dominate much of his compositional output for the following 12 years.
On 17 May 1888, Mahler suddenly resigned his Leipzig position after a dispute with the Stadttheater's chief stage manager, Albert Goldberg. However, Mahler had secretly been invited by Angelo Neumann in Prague (and accepted the offer) to conduct the premiere there of "his" Die drei Pintos, and later also a production of Peter Cornelius's Der Barbier von Bagdad. This short stay (July–September) ended unhappily, with Mahler's dismissal following his outburst during a rehearsal. However, through the efforts of an old Viennese friend, Guido Adler, and cellist David Popper, Mahler's name went forward as a potential director of the Royal Hungarian Opera in Budapest. He was interviewed, made a good impression, and was offered and accepted (with some reluctance) the post from 1 October 1888.
In the early years of Mahler's conducting career, composing was a spare time activity. Between his Laibach and Olmütz appointments he worked on settings of verses by Richard Leander and Tirso de Molina, later collected as Volume I of Lieder und Gesänge ("Songs and Airs"). Mahler's first orchestral song cycle, Lieder eines fahrenden Gesellen, composed at Kassel, was based on his own verses, although the first poem, "Wenn mein Schatz Hochzeit macht" ("When my love becomes a bride") closely follows the text of a Wunderhorn poem. The melodies for the second and fourth songs of the cycle were incorporated into the First Symphony, which Mahler finished in 1888, at the height of his relationship with Marion von Weber. The intensity of Mahler's feelings is reflected in the music, which originally was written as a five-movement symphonic poem with a descriptive programme. One of these movements, the "Blumine," later discarded, was based on a passage from his earlier work Der Trompeter von Säckingen. After completing the symphony, Mahler composed a 20-minute symphonic poem, Totenfeier "Funeral Rites", which later became the first movement of his Second Symphony.
On arriving in Budapest in October 1888, Mahler encountered a cultural conflict between conservative Hungarian nationalists who favoured a policy of Magyarisation, and progressives who wanted to maintain and develop the country's Austro-German cultural traditions. In the opera house a dominant conservative caucus, led by the music director Sándor Erkel, had maintained a limited repertory of historical and folklore opera. By the time that Mahler began his duties, the progressive camp had gained ascendancy following the appointment of the liberal-minded Ferenc von Beniczky as intendant. Aware of the delicate situation, Mahler moved cautiously; he delayed his first appearance on the conductor's stand until January 1889, when he conducted Hungarian-language performances of Das Rheingold and Die Walküre to initial public acclaim. However, his early successes faded when plans to stage the remainder of the Ring cycle and other German operas were frustrated by a renascent conservative faction which favoured a more traditional "Hungarian" programme. In search of non-German operas to extend the repertory, Mahler visited in spring 1890 Italy where among the works he discovered was Pietro Mascagni's recent sensation Cavalleria rusticana (Budapest premiere on 26 December 1890).