Adam O'Reilly's goal in the third minute of stoppage time earned St Patrick's Athletic a huge three points in the race for Europe against Dundalk at Casey's Field.
The game looked to be heading towards a draw until the on-loan Preston North End midfielder pounced with virtually the last kick of the game to help Tim Clancy's side close the gap to their opponents in third to a single point with four games remaining.
While fourth may well be good enough for Europe if Derry City win the FAI Cup, neither of these sides will want to rely on that lottery.
A first home defeat of his reign was a harsh blow on Stephen O'Donnell's side, who were the better side throughout.
Chris Forrester had given them a 20th minute lead against the run of play but it was deservedly cancelled out by local youngster Ryan O'Kane in first-half stoppage time.
O'Kane looked like he would be in again at the end but a brilliant challenge from Sam Curtis prompted a break which resulted in O'Reilly turning the ball home from about four yards out, sparking a pitch invasion from the away support.
While Dundalk remain in third, the form is with Pat's in what is set to be a real race to qualify for next season's Europa Conference League qualifiers.
It was the home side who started on top with Steven Bradley firing just wide after 68 seconds after Adam O'Reilly had been caught in possession.
O'Kane then threatened for the first time on 10 minutes when he turned Sam Curtis inside out at the edge of the box before shooting just over.
John Martin then had an effort deflect just wide with Danny Rogers wrongfooted two minutes later before Pat's took the lead with their first attempt on 20 minutes.
Sam Bone, a Cup winner with the Inchicore side last season, was guilty of needlessly giving the ball away at the back after panicking following a poor touch and the visitors punished the error with Anto Breslin teeing up Forrester for a shot that flashed to the top left hand corner.
Greg Sloggett, played his 100th game in Dundalk colours, went close to levelling eight minutes later when he was picked out in the box from a short corner by Bradley but his effort was parried by Rogers before being hooked to safety by Eoin Doyle.
Dundalk had penalty appeals turned away on 41 minutes when Bradley went down in the box following a coming together with Breslin but referee Damien MacGraith was uninterested.
The Louth men would draw level in the first minute of stoppage time when O'Kane cut in from the left onto his right foot to fire low across Rogers to the bottom right hand corner - becoming the first local man to score a league goal for the club since Tiarnan Mulvenna in July 2013.
Joe Adams then almost put Dundalk ahead seven minutes after the restart with a curling effort from just outside the box that flashed just wide of the left hand post with Rogers beaten.
Bradley had another effort blocked in the box before Alfie Lewis volleyed over after a corner broke to him on the edge of the box in the 78th minute.
Pat's only real chance came four minutes later when Forrester's corner picked out Joe Redmond but the centre-half's scuffed effort was turned behind by Martin.
They would emerge victorious, however, when O'Reilly popped up with a late, late winner from Ben McCormack's cut back that could prove crucial come the end of the season.
© rte.ie