It is the second consecutive time Germany are failing to qualify from the group stage at the World Cup.
It was an emotional return for Costa, who gained a fearsome reputation during his three years stint at Stamford Bridge before he left in 2017.
The game ended even more dramatically at the final whistle as Conte and Tuchel were shown red cards for a scuffle.
“It was a deserved defeat. We weren’t good today. We didn’t defend well and lost too many balls,” Bayern Munich coach Julian Nagelsmann said.
Both sides are building towards the World Cup, and the competition will have its group stage drawn on Friday in Doha.
Chelsea said with the win against Lille, that they were geared up for the Carabao Cup final with Liverpool on Sunday.
The game ended 2-1 as Palmeiras defender Luan was shown the red card in added time.
Kai Havertz scored just five minutes after the blast of the whistle, giving the Blues a lead at the Bridge.
Juventus stay top of Group H, while Chelsea are second on the group table with 3 points in from two games.
Chelsea held Liverpool to a 1-1 draw at Anfield in their English Premier League game on Saturday.