* Hamburg go into relegation playoff
* Lewandowski scores twice in his last Dortmund league match
* Schalke qualify for Champions League
* Wolfsburg, Moenchengladbach and Mainz into Europa League (Adds details)
By Brian Homewood
May 10 (Reuters) - Hamburg SV, the Bundesliga's only ever-present club, escaped direct relegation by the skin of their teeth on Saturday after a 3-2 defeat at Mainz 05 sent them into a two-leg playoff against a second division team.
Nuremberg and Eintracht Braunschweig, who started the final day of the league season below Hamburg but could have moved above them with wins, were relegated after losing 4-1 at Schalke 04 and 3-1 at Hoffenheim respectively.
Schalke 04's victory clinched third place and sent them straight into the Champions League group stage next season, while Bayer Leverkusen finished fourth with a 2-1 triumph over Werder Bremen to qualify for the playoff round.
Poland striker Robert Lewandowski, playing his last league game for second-placed Borussia Dortmund before moving to champions Bayern Munich next season, scored twice in a 4-0 win at Hertha Berlin to finish as Bundesliga top scorer with 20.
Bayern beat VfB Stuttgart 1-0 with a stoppage time goal from evergreen Peru striker Claudio Pizarro to complete their 34-match campaign with 29 wins, three draws and two defeats.
Hamburg, who have never been relegated in the Bundesliga's 51-year history, clung on despite losing their last five games, helped by equally poor form from their rivals.
Nuremberg lost their last seven while Braunschweig, who went straight back down after being promoted last season, also ended with five consecutive losses.
Hamburg, the so-called Bundesliga Dinos (dinosaurs), finished 16th with 27 points anead of Nuremberg on 26 and Braunschweig with 25. Bayern's tally hit 90 points, 19 clear of Dortmund, followed by Schalke on 64 and Leverkusen with 61.
Leverkusen edged out VfL Wolfsburg, 3-1 winners over Borussia Moenchengladbach, by one point. Wolfsburg, Moenchengladbach and Mainz qualified for the Europa League.
Hamburg's defence has been calamitous all season and they messed up again when a dreadful misunderstanding between Heiko Westermann and Rene Adler allowed Elkin Soto to nip in and put Mainz ahead after seven minutes.
Pierre-Michel Lasogga headed Hamburg level five minutes later after Rafael van der Vaart's shot was parried by Loris Karius and the visitors dominated the rest of the half.
Mainz regained the lead when Yunus Malli scored with a low shot from the edge of the area in the 65th and a brilliant individual goal by Shinji Okazaki, the Japanese forward's 15th in the league this term, made the game safe with eight minutes left.
Ilo Ilicevic pulled one back for Hamburg in the 84th minute.
A sixth-minute header by Joel Matip sent Schalke on their way before Roman Neustaedter, Julian Draxler and Chinedu Obasi shared the other goals and Josip Drmic replied for Nuremberg.
There was no way back for Braunschweig, either, as they also went behind to an early goal with Sebastian Rudy heading in after 15 minutes for free-scoring Hoffenheim.
Roberto Firmino volleyed the second and Kevin Volland scored an easy third as Hoffenheim finished the season with 72 goals scored and 70 conceded.
Lewandowski opened his account four minutes before halftime when he was sent clear by a Mats Hummels pass and he was on target again with a free kick in the 80th minute. Milos Jojic and Henrikh Mkhitaryan shared the other Dortmund goals. (Reporting by Brian Homewood; editing by Justin Palmer and Josh Reich)