Costa's ferocious dipping shot from 30 metres out on 71 minutes was the bright highlight of a lacklustre Bayern display.
Douglas Costa's long-range strike rescued Bayern Munich in their 1-0 victory at bottom side Darmstadt on Sunday to reinstate his side as Bundesliga leaders before RB Leipzig showdown.
Bayern host second-placed Leipzig at the Allianz Arena on Wednesday in a mouth-watering clash with both teams on 36 points, but the Bavarians lead on goal difference.
Costa's ferocious dipping shot from 30 metres out on 71 minutes was the bright highlight of a lacklustre Bayern display as Darmstadt battled their illustrious opponents, running seven kilometres more as a team.
Carlo Ancelotti's Bayern had been temporarily usurped from top spot in Germany for 24 hours by Leipzig's impressive 2-0 win at home to Hertha Berlin on Saturday.
However, this was a below-par display from Bayern, especially in the first half, against a limited Darmstadt team who suffered their seventh straight league defeat.
"We are relieved, they were three important points, it would have been hard to have played Leipzig without them," said Bayern goalkeeper Manuel Neuer.
"But the way we played -- that wasn't FC Bayern."
With Jerome Boateng already out after needing a shoulder operation, Bayern's captain Philipp Lahm withdrew just before kick-off after pulling a thigh muscle in the warm-up and was replaced at right-back by Rafinha.
With an eye on Leipzig, Ancelotti rotated with both Germany midfielder Joshua Kimmich and Franck Ribery starting on the bench.
The Italian coach had demanded a performance with "maximum intensity", but Bayern did exactly the opposite, failing to create a clear chance in the opening 25 minutes at the Boellenfalltor stadium.
Bayern lacked a creative spark and Costa made little inroads into the Darmstadt defence, until his thunderbolt of a shot settled the result.
"We didn't play well, we weren't fast enough, but it was important for us to win and to stay top," said Ancelotti.
"We must play better, quickly and give our best on Wednesday."
Bayern's hot-shot striker Robert Lewandowski was harassed by Darmstadt defenders whenever he got the ball.
Ancelotti resorted to his prefered 4-3-3 formation, even though some of Munich's biggest wins this season have been achieved with a 4-2-3-1 line-up.
Darmstadt's caretaker coach Ramon Berndroth admitted he "idolised Ancelotti as a youngster", but his side showed little respect, created a few half chances and never allowed Munich's stars time on the ball.
Franck Ribery came on for the ineffective Arturo Vidal for the final 20 minutes just before Costa's superb winner.
Thomas Mueller pulled defenders away from the middle and with a clear view of goal, Costa unleashed a fierce shot from well outside the area which dipped inside the top left-hand corner.
Darmstadt's best chance came when midfielder Peter Niemeyer headed straight at Neuer from a free-kick on 77 minutes.
Bayern defender Mats Hummels admitted his side must improve before the Leipzig showdown.
"The respect is huge and it's going to be a demanding test. We will have to put in a top performance, a standard one isn't going to be good enough against a team like that," said the centre-back.
Later, Ingolstadt, who beat RB Leipzig 1-0 last weekend, pulled off another shock win with a 2-1 victory at 10-man Bayer Leverkusen.
US midfielder Alfredo Morales gave Ingolstadt the lead at the BayArena before Leverkusen's Chile hardman Charles Aranguiz was sent off just after the break for his second booking.
Swiss striker Admir Mehmedi equaliser after burying Julian Brandt's superb pass, but Israel midfielder Almog Cohen netted Ingolstadt's winner on 73 minutes.
The result pulls Ingolstadt up to 16th, still in the bottom three, while Leverkusen are ninth.