Patrick Hoban's late, late winner broke Sligo Rovers' resistance at Oriel Park as Dundalk returned to winning ways in dramatic fashion.
It looked like Ger Lyttle's side had done enough to go back to the west with a point but with 89 minutes on the clock, Hoban glanced home a Dane Massey cross to take his tally to 11 for the season.
There was almost time for another late twist and the visitors almost hit back in stoppage time when Adam Morgan guided a header towards goal in the 94th minute only to see Dean Jarvis knock it clear.
The first-half was a tale of two penalties. Hoban moved into double figures with a 23rd minute spot-kick but Dundalk, just as they were in Waterford seven days earlier, conceded in the 47th minute of the half when Rhys McCabe scored from the opposite spot.
Stephen Kenny's side had a host of chances to win the game but a combination of some poor finishing, good goalkeeping and last ditch defending looked like it would leave the Lilywhites frustrated until Hoban did the business yet again in the dying stages.
The hosts opened brightly and almost pulled in front in the eighth minute when Brian Gartland angled a volley at goal but the unsighted Mitchell Beeney made a fine stop.
Dundalk continued to press and they went ahead in the 23rd minute when Dylan Connolly was upended by Patrick McClean and Hoban produced a John Aldridge style shimmy to bury his spot kick past Beeney.
The Bit o'Red responded positively to the blow and Gary Rogers - who moved level with Jason Byrne on 507 league appearances - was called into action when Gary Boylan came in from the right to let fly but the Dundalk keeper touched the ball around the post.
Lyttle and his staff were then up in arms when Caolan McAleer was left flattened by Rogers. Referee Tom Connolly waved play on but Sligo's luck changed in stoppage time as some ragged defending cost Dundalk for the second week on the trot.
McAleer pounced on Stephen Folan's weak header to skip around Rogers. He went down and Connolly, after seeing his assistant flag, eventually pointed to the spot, with Rhys McCabe rattling home a deserved equaliser.
Dundalk emerged for the second-half with a spring in their step and Connolly waved away another penalty shout in the 54th minute when Hoban was grounded by John Mahon after reacting to Duffy's quick throw.
Kenny's side started to tun the screw and they should have went back in front on the hour mark when Benson put the ball on a plate for Ronan Murray but he could only sidefoot it wide with the goal gaping.
Substitute Jamie McGrath was denied by the legs of Beeney and with nine minutes to go, Dylan Connolly blazed a stunning Massey cross over the top.
It looked like the points would be shared but Hoban gave another fine Massey cross the finish it deserved to move Dundalk a point behind Cork City in second place.
DUNDALK: Gary Rogers; Sean Hoare, Brian Gartland, Stephen Folan (Dane Massey 56), Dean Jarvis; Chris Shields (Marco Tagbajumi 79), Robbie Benson; Dylan Connolly, Ronan Murray (Jamie McGrath 66), Michael Duffy; Patrick Hoban.
SLIGO ROVERS: Mitchell Beeney; Gary Boylan, Kyle Callan-McFadden, John Mahon, Patrick McClean (Jack Keaney 42), Regan Donelon; David Cawley, Rhys McCabe, Caolan McAleer, Raffaele Cretaro (Adam Wixted 67); Gregory Moorhouse (Adam Morgan 59).
Referee: Tomas Connolly.