Ross County moved up to seventh place in the Scottish Premier League with a hard-fought win over basement side Dundee at Dens Park.
Gary Harkins, back at Dundee after his spell at Kilmarnock, fired over the bar in a rare first-half chance for the home side as County had the upper hand.
Paul Lawson's powerful shot rattled down off the crossbar and was deemed to have crossed Rab Douglas's goal-line.
And deep into injury-time Gary Glen controlled a long kick-out to score.
This was a match Dundee really needed to win yet they got off to a bad start when Lewis Toshney, on loan from Celtic, was sloppy with his back-pass to Douglas in the first minute.
County midfielder Rocco Quinn was quick to pounce but the home keeper managed to race off his line to clear the danger.
That signalled a hectic night for Douglas, who made good first-half stops from County's Mihael Kovacevic and Sam Morrow.
As half-time neared, Harkins shifted the ball between his feet neatly to fire a fierce left-foot effort just over Mark Brown's bar.
In the second half Morrow lobbed wide of the Dundee goal when he seemed certain to score and substitute Steffen Wohlfarth lifted his effort high over the bar when he went one on one with Douglas.
Douglas was busy again a few minutes later, first parrying a ball away to his right and then springing forward to block a Morrow shot.
Dundee had chances, though, and Brian Easton volleyed over from 16 yards on the hour mark when better composure might have helped him to find the target and John Baird also headed high over as the ball fell to him with only the keeper to beat.
County were always threatening and Lawson brought a good save from Douglas in 67 minutes, closely followed by a timely Gary Irvine block from Iain Vigurs' driven shot.
However, two late goals were enough to give County the points, propelling them level on points with sixth-placed Aberdeen and leaving Dundee marooned at the bottom of the table 14 points adrift of St Mirren.
Live Text Commentary
Full Time The game is over, as the referee blows his whistle.90:00 +2:39
The assist for the goal came from Grant Munro.90:00 +2:39 Goal scored
Goal! - Gary Glen - Dundee 0 - 2 Ross Co Gary Glen finds the net with a goal from inside the area to the bottom left corner of the goal. Dundee 0-2 Ross County.90:00 +0:27
Corner taken by James McAlister from the left by-line.89:37
Richard Brittain fouled by Iain Davidson, the ref awards a free kick. Richard Brittain takes the direct free kick.82:14 Substitution
Substitution Stuart Kettlewell comes on in place of Iain Vigurs.80:36 Booking
Booking Rab Douglas booked for unsporting behaviour.79:53
Assist by Iain Vigurs.79:53 Goal scored
Goal! - Paul Lawson - Dundee 0 - 1 Ross Co Goal scored by Paul Lawson from just inside the area to the bottom right corner of the goal. Dundee 0-1 Ross County.79:28
The official flags James McAlister offside. Mark Brown restarts play with the free kick.78:58
Richard Brittain gives away a free kick for an unfair challenge on Brian Easton. The free kick is swung in right-footed by Gary Harkins.77:34 Substitution
Substitution Mark Stewart replaces Kevin McBride.74:18
Declan Gallagher takes the free kick.74:18 Booking
Booking Richard Brittain shown a yellow card.73:25
Free kick taken by Gary Irvine. Free kick awarded for a foul by Richard Brittain on Kevin McBride.73:25 Booking
Booking Iain Vigurs goes into the referee's book.73:24
Iain Vigurs gives away a free kick for an unfair challenge on Nicky Riley.72:09
Free kick awarded for an unfair challenge on Gary Harkins by Scott Boyd. Kevin McBride delivers the ball from the free kick right-footed from left channel, save by Mark Brown.70:55
Strike on goal comes in from Richard Brittain from the free kick.70:55 Booking
Booking Kevin McBride goes into the referee's book.
Iain Vigurs fouled by Kevin McBride, the ref awards a free kick.67:16 Substitution
Substitution Gary Glen replaces Sam Morrow.66:46
Paul Lawson takes a shot. Save by Rab Douglas.65:48
Iain Davidson takes a shot. Save made by Mark Brown.61:02
Nicky Riley fouled by Iain Vigurs, the ref awards a free kick. A cross is delivered by Kevin McBride, Effort on goal by Brian Easton from just inside the area clears the crossbar.60:02
Kevin McBride gives away a free kick for an unfair challenge on Iain Vigurs. The free kick is delivered left-footed by Iain Vigurs from right channel.56:49 Substitution
Substitution Nicky Riley replaces Colin Nish.52:05
Steffen Wohlfarth has an effort at goal from deep inside the area missing to the left of the target.48:20
Shot from inside the area by Sam Morrow clears the bar.45:01
The second half kicks off.45:01 Substitution
Substitution Steffen Wohlfarth joins the action as a substitute, replacing Alex Cooper.45:00 +0:23 Half time
Half Time It is the end of the first-half.43:44
Shot from outside the area by Gary Harkins misses to the left of the goal.37:53
Corner taken by James McAlister from the right by-line to the near post.37:04
Corner from the left by-line taken by Richard Brittain, save by Rab Douglas.31:16
Richard Brittain takes a shot. Save made by Rab Douglas. Inswinging corner taken by Richard Brittain, Declan Gallagher manages to make a clearance. Corner taken by Richard Brittain from the left by-line.30:26
Corner taken by Richard Brittain, clearance made by Gary Irvine.4:39
Handball by Kevin McBride. Free kick crossed right-footed by Richard Brittain from left channel, Rab Douglas makes a save.1:21
Rocco Quinn has an effort at goal from outside the penalty box missing to the wide right of the target.0:00
The referee gets the game started.
Live data and text provided by our data suppliers