(CNN) -- Pep Guardiola surely faces the most thankless task in world football after Bayern Munich clinched a historic treble on Saturday, adding the German Cup to the Champions League and Bundesliga crowns.
The Spaniard, who was named as Bayern's next coach back in January, will take over a team that has conquered Europe and its domestic rivals, with the 3-2 win over Stuttgart giving the departing Jupp Heynckes a perfect sendoff.
The 68-year-old is widely expected to retire, though he has also been linked with a return to Real Madrid -- where he won the Champions League in 1998 -- after guiding the Bavarians to 45 wins from 53 matches this season.
Stuttgart never looked like inflicting Bayern's fourth defeat of the campaign after going 3-0 down after an hour, with Thomas Muller netting a first-half penalty and striker Mario Gomez scoring twice against his former club in what could prove to be his final game for Bayern.
Austrian Martin Harnik struck twice to give Stuttgart hope in front of more than 74,000 fans at Berlin's Olympic Stadium, but Bayern held on for a 16th victory in the knockout competition to become the first German side to complete such a treble.
Guardiola helped Barcelona become the first Spanish club to win a hat-trick of titles in 2011, but was unable to follow that up last season before standing down.
Barca completed this season in style on Saturday, beating Malaga 4-1 to equal Real's points record of 100 and beat the club's best goals tally -- scoring 115 in 38 La Liga games.
Striker David Villa, Cesc Fabregas and young defender Martin Montoya all netted within 16 minutes, while veteran midfielder Andres Iniesta curled in a spectacular second-half effort before substitute Pedro Morales pulled one back for Malaga.
Eric Abidal came on to make his final appearance for Barca, with the French defender being released despite making his comeback in April following a liver transplant.
Villa's future is also in doubt, with Barca having signed Brazil forward Neymar from Santos last week.
Malaga manager Manuel Pellegrini is also on the move, being widely expected to join English club Manchester City. The Chilean announced last month that he is leaving the Spanish club, which ended the season in sixth place and reached the Champions League quarterfinals.
Jose Mourinho's three-year tenure at Real Madrid ended with a 4-2 win at home to Osasuna, which left his second-placed side 15 points behind Barcelona.
The Portuguese coach, who is expected to rejoin English club Chelsea, was booed by large sections of home fans before the match -- though others held banners thanking him -- and he was surrounded by photographers every time he ventured from the dugout.
He has divided opinion at the Santiago Bernabeu after being unable to follow up last season's title, or deliver Real's long-awaited 10th European title -- and the Copa del Rey final defeat against Atletico Madrid was the last straw as he agreed to leave by mutual consent.
Despite Mourinho's apparent dressing room rift with former captain Iker Casillas and other key Spanish players, Real defender Alvaro Arbeloa said the 50-year-old deserved respect.
"We respect his decision, the club's too, and wish him well. We all know that we have taken a major leap in competitiveness and we knew we could have achieved a lot, but due to small details or bad luck it was not to be," Arbeloa said.
"He has had his successes and failures, as we have all had, but he gave his all and defended Real Madrid above everything."
Real Sociedad snatched a place in the Champions League qualifying rounds, winning 1-0 at Deportivo la Coruna to ensure Valencia missed out after a 4-3 defeat at Sevilla.
Striker Alvaro Negredo scored all four goals for mid-table Sevilla as visiting Valencia dropped to fifth place despite a second-half double from forward Roberto Soldado.
The defeat relegated second bottom Deportivo, while Mallorca also went down despite winning 4-2 against Valladolid.
Celta Vigo moved out of the bottom three with a 1-0 win over Espanyol, but Zaragoza ended the season at the foot of the table after losing 3-1 at home to third-placed Atletico.