A controversial 84th minute penalty by Eddie Gormley ended Bohemians' 16-match unbeaten run and any lingering hope that they might have had of catching Shelbourne. For St Patrick's Athletic it was their first victory in 11 Dublin derby games this season and boosted their hopes of European football next year.
This Dalymount Park encounter in front of the live TV cameras appeared to be drifting to a tame scoreless draw when St Patrick's Athletic winger Ger McCarthy, apparently in an offside position, cut inside central defender Shaun Maher, only to be taken down inside the box.
For his trouble Maher was shown the red card by Dublin referee John McDermott with the Bohemians players furiously protesting about the linesman failing to raise his flag with McCarthy in that offside position.
St Pat's had gone close early on when Bohemians defender Tony O'Connor lost possession in midfield. Alan McNevin out-sprinted Maurice O'Driscoll to fire in a shot from 20 yards pushed round the post by goalkeeper Michael Dempsey.
That was typical of the heroics by Dempsey, who prior to last night had kept 10 clean sheets in 11 appearances for the club this season.
The first real moment of danger for the visitors came after Colm Hawkins fouled Stephen Caffrey. The resulting free kick from 25 yards by Paul Byrne was pushed away by St Pat's goalkeeper Trevor Wood.
Dempsey again came to Bohemians' rescue when going full stretch to finger-tip a header from Marcus Hallows round the upright following a precise cross from Dessie Byrne on the left.
Glen Crowe headed just over for Bohemians immediately after the interval after a Gareth O'Connor cross in a move started by the always inventive Byrne.
Both sides wasted clear-cut openings, notably Ray Kelly for Bohemians and then McCarthy with an equally important miss for St Pat's.
Then came the drama of that late winner that will have been music to Shelbourne's ears as the Tolka Park club close in on the title. A victory over lowly Sligo Rovers at the Showgrounds on Sunday will put them 11 points clear with only four games remaining.
BOHEMIANS: Dempsey; T O'Connor, Maher, O'Driscoll, Brunton; P Byrne, Hunt, Caffrey, G O'Connor; R Kelly, Crowe. Subs: Vaudequin for P Byrne (59), Harris for R Kelly (83), John for Brunton (87).
ST PATRICK'S: Wood; Burke, McGuinness, Hawkins, D Byrne; Prenderville, Osam, Gormley; McCarthy, Hallows, McNevin. Subs: L Kelly for McNevin (45), Croly for Hallows (73).
Referee: John McDermott (Dublin).