Runaway Bundesliga leaders Bayern Munich had their 20-match unbeaten run in all competitions ended at Hoffenheim on Tuesday as Andrej Kramaric's winner sealed the hosts' historic 1-0 victory.

Bayern's run came to an end a week before their mouth-watering Champions League home leg quarterfinal against Real Madrid.

This was Bayern's first loss since going down 3-2 at Russia's Rostov in a Champions League group game last November.

It was also only their second defeat in 27 German league games having also stumbled at Borussia Dortmund, but they still hold a 13-point lead in the table.

"Of course, we shouldn't have allowed that to happen," fumed Bayern's captain-for-the-night Arjen Robben.

"It was better in the second half, but the ball wouldn't go in.

"Our lead (in the table) is still big, but that was an unnecessary defeat."

Second-placed RB Leipzig can now trim Bayern's massive lead at Mainz on Wednesday.

This was Hoffenheim's first win over Bayern at the 18th attempt.

Having earned a 1-1 draw in Munich last November, this is another feather in the cap for Hoffenheim's 29-year-old coach Julian Nagelsmann.

"It always sounds good to beat Bayern, we went close in the first match, it was a good bit of work for us," said Nagelsmann, Germany's coach of the year for 2016.

"Kramaric had a great game, he scored with the worse chance in the first half for us.

"I said we had to be brave, which we had, but we also played the better football."

With a busy run of fixtures approaching, Bayern coach Carlo Ancelotti rotated his squad, but still started with 10 internationals.

Bayern host Dortmund in the Bundesliga on Saturday, then Real next Wednesday.

With Germany goalkeeper Manuel Neuer recovering from minor foot surgery, reserve shot-stopper Sven Ulreich, the only uncapped player in the starting team, again deputised.

Captain Philipp Lahm, Jerome Boateng and Franck Ribery started on the bench.

Playmaker Thiago Alcantara was rested while Thomas Mueller was sidelined by an ankle injury.

Hoffenheim took advantage of Bayern's changes by dominating the opening half and took a deserved lead on 21 minutes.

A poor clearance from Bayern defender Mats Hummels was snapped up by ex-Leicester City striker Kramaric who slammed his shot past Ulreich.

Bayern's striker Robert Lewandowski hit the crossbar just before the break after Kingsley Coman whipped in a cross.

With time running out, Lewandowski forced Hoffenheim goalkeeper Oliver Baumann into a superb diving save as they hunted the equaliser.

Hoffenheim strengthen their hold on third place and are set to make their Champions League debut next season.