Patrick Hoban's last-gasp penalty sank Bohemians at Oriel Park to give Dundalk a priceless victory.
With the game in the fourth minute of injury time, Sean Gannon was upended by Paddy Kirk and Hoban sent James Talbot the wrong way from 12 yards to snatch all three points.
It was a bitter pill for the visitors to swallow. Despite making seven changes to the team that beat Finn Harps on Friday night, Bohs were much better in every department against a Dundalk side that came into the game on the back of two straight defeats.
Starting the game 13 points behind leaders Shamrock Rovers, this was a chance for Vinny Perth's side to make up some ground and even though they huffed and puffed, the celebration that followed Hoban's penalty was an indication of how important this goal could prove to be.
Perth threw something of a curveball by naming Sean Gannon on the right-hand side of an unfamiliar looking three-man defence but Dundalk almost found themselves behind after just four minutes.
Keith Buckley was afforded space to pick out Danny Mandriou but he couldn't keep his header on target despite finding himself unmarked in the penalty area.
Hoban headed a Flores free-kick over the top in the 10th minute but Dundalk were second best for much of the half with a number of misplaced passes leading to groans from the home support.
In contrast, the visitors knocked the ball around with confidence and they passed up another gilt-edged chance to go in front with 35 minutes played. Sean Hoare's slip allowed Ali Reghba to take possession. His cross to the far post located Kevin Devaney but he could only stab his close-range effort into the side netting.
Perth shelved the defensive experiment as the half came to a close and Michael Duffy, who was well shackled by Andy Lyons, showed brief signs of flickering into life but Bohs goalkeeper Talbot enjoyed a relatively stress-free half.
Chris Shields and Patrick McEleney were introduced in the opening 15 minutes of the second half but it was the visitors who continued to look the more likely.
Gary Rogers had to tip a Ryan Swan effort behind on the hour mark after an incisive run by Mandriou had the Dundalk back four back peddling with Rob Cornwall flashing a header just over from the corner that followed.
Bohs continued to knock at the door and Mandriou's swerving free-kick asked questions of Rogers. The goalkeeper was then thankful for the intervention of Gannon to clear a vicious Reghba cross that evaded his reach.
Things became stretched in the final 15 minutes and Dundalk were let off the hook again when Shields coughed up possession to Mandriou but the youngster couldn't pick a pass to release Swan.
It looked like the only winners on the night would be Rovers but Oriel Park erupted when Hoban dispatched his effort from 12 yards to settle a pulsating affair.
Dundalk: Gary Rogers; Sean Gannon, Sean Hoare, Daniel Cleary; Joe McKee (Chris Shields 56), Jordan Flores (Patrick McEleney 59); John Mountney (Daniel Kelly 73), Jamie McGrath, Michael Duffy, Dean Jarvis; Patrick Hoban.
Bohemians: James Talbot; Andy Lyons, Aaron Barry, Rob Cornwall, Paddy Kirk; Robbie McCourt, Keith Buckley; Ali Reghba (Danny Grant 74), Danny Mandriou (Scott Allerdice 90), Kevin Devaney; Ryan Swan (Sam Byrne 86).
Referee: Tom Connolly.