St Johnstone extended their unbeaten away run to five games with victory over 10-man Kilmarnock.
But the match will be remembered for the controversial sending off of Kilmarnock captain Manuel Pascali.
Murray Davidson opened the scoring for the visitors, but Michael Nelson thought he had rescued a point with his second half header.
Rowan Vine's toe-poked finish with two minutes remaining saw the Perth side claim all three points.
Pascali was shown a straight red card by referee Stevie O'Reilly after six minutes for a robust challenge on Nigel Hasselbaink.
It looked as though Pascali took the ball cleanly, but the referee disagreed and brandished the red card.
Kenny Shiels was furious and a few minutes later was sent to the stand.
With their numerical advantage, St Johnstone enjoyed most of the early possession as Kilmarnock had to reshuffle their pack.
The visitors could have taken the lead with chances for Gregory Tade and Liam Craig - Cammy Bell standing firm in the Killie goal on both occasions.
But the pressure finally told after half an hour; Tade scuffed a shot on the edge of the box and Davidson swept home from 10 yards.
St Johnstone might have doubled their lead had they been awarded a penalty just five minutes later, but the referee instead booked Vine for diving when it looked as though he was illegally felled in the box.
Perhaps feeling an element of injustice during the half-time interval, Kilmarnock came out for the second period looking vibrant and striker Paul Heffernan came close for the hosts.
He ghosted past two St Johnstone defenders before unleashing a vicious shot from 20 yards that was palmed away by Alan Mannus.
Cillian Sheridan also came close to equalising, but his snap shot volley from a tight angle arched high and wide.
With an increasing freedom about their play, Kilmarnock left space for their opponents to exploit, and both Liam Craig and Chris Millar had chances to cement the three points.
From his adopted position in the stand which was in fact just behind the dugout, Kenny Shiels urged his side forward as the game entered its final stages.
And their endeavour was rewarded with 10 minutes remaining when Nelson rose to nod beyond Mannus.
At that stage it looked as though there would only be one winner as Killie pressed for an unlikely three points.
But given the cruel fate that football often conjures up, St Johnstone, against the run of play, stole a victory with two minutes remaining.
Millar played through Vine, and as Bell rushed from his goal, the substitute poked past the Kilmarnock goalkeeper.
Sorry, we were unable to load match stats, please try again.
Live Text Commentary
Full Time The game is over, as the referee blows his whistle.90:00 +0:58
Mohamadou Sissoko fouled by Gary Miller, the ref awards a free kick.90:00 +0:55
Cameron Bell restarts play with the free kick.90:00 +0:55 Booking
Booking Gary Miller is cautioned.88:36
Assist by Chris Millar.88:36 Goal scored
Goal! - Rowan Vine - Kilmarnock 1 - 2 St J'stone Rowan Vine finds the net with a goal from the edge of the penalty area to the bottom right corner of the goal. Kilmarnock 1-2 St Johnstone.87:27 Substitution
Substitution David Robertson replaces Liam Craig.84:37
Corner from left by-line taken by James Dayton.84:04
The assist for the goal came from James Dayton.84:04 Goal scored
Goal! - Michael Nelson - Kilmarnock 1 - 1 St J'stone Michael Nelson finds the back of the net with a headed goal from close in. Kilmarnock 1-1 St Johnstone.83:39
Foul by David MacKay on James Dayton, free kick awarded. James Dayton sends in a cross,80:11 Substitution
Substitution Gregory Tade goes off and Gary Miller comes on.80:11 Substitution
Substitution (Kilmarnock) makes a substitution, with James Dayton coming on for Jeroen Tesselaar.80:11 Substitution
Substitution Danny Racchi replaces Borja Perez.77:06
Free kick awarded for an unfair challenge on Steven MacLean by Michael Nelson. Callum Davidson restarts play with the free kick.76:01
Chris Millar is caught offside. Cameron Bell restarts play with the free kick.73:22
Murray Davidson takes a shot. Save by Cameron Bell. Corner taken by Rowan Vine from the right by-line, Unfair challenge on Mohamadou Sissoko by Steven Anderson results in a free kick. Free kick taken by Cameron Bell.71:45
Outswinging corner taken left-footed by Liam Craig from the left by-line, free kick awarded for a foul by Steven MacLean on Cameron Bell. Cameron Bell takes the free kick.71:12
Foul by Gary Harkins on Rowan Vine, free kick awarded. Direct free kick taken by Steven Anderson.68:55
Cillian Sheridan produces a right-footed shot from close range which goes wide of the right-hand post.
Borja Perez takes the free kick.68:09 Booking
Booking Caution for Steven MacLean.68:07
Foul by Steven MacLean on Paul Heffernan, free kick awarded.67:06
Foul by Mohamadou Sissoko on Gregory Tade, free kick awarded. Steven MacLean produces a strike on goal direct from the free kick, Cameron Bell makes a save.65:31
Free kick awarded for a foul by Michael Nelson on Frazer Wright. Alan Mannus takes the free kick.65:07
Outswinging corner taken right-footed by Borja Perez from the right by-line, Frazer Wright makes a clearance.64:26
The free kick is delivered right-footed by Borja Perez from left wing, Steven Anderson makes a clearance.64:26 Booking
Booking David MacKay booked for unsporting behaviour.64:15
David MacKay gives away a free kick for an unfair challenge on Gary Harkins.63:02
Free kick awarded for a foul by Jeroen Tesselaar on Rowan Vine. Free kick taken by David MacKay.62:27
Inswinging corner taken right-footed by Borja Perez, Liam Craig manages to make a clearance.60:54
The offside flag is raised against Steven MacLean. Indirect free kick taken by Cameron Bell.59:32
Corner taken by Borja Perez, Strike from close range by Mohamadou Sissoko clears the bar.58:58
Steven MacLean has an effort at goal from close range which goes wide right of the target.58:14
Free kick awarded for an unfair challenge on Cillian Sheridan by Steven Anderson. Direct free kick taken by Gary Harkins.57:12
Shot by Liam Craig from deep inside the penalty area misses to the left of the goal.55:29
Liam Craig has an effort at goal from outside the penalty box which goes wide right of the target.54:18
Borja Perez takes a outswinging corner from the right by-line played to the near post.53:14
Murray Davidson gives away a free kick for an unfair challenge on Gary Harkins. Gary Harkins restarts play with the free kick.52:22
Borja Perez takes a shot. Save by Alan Mannus.50:15
Steven MacLean challenges Borja Perez unfairly and gives away a free kick. Michael Nelson takes the free kick.47:54
Unfair challenge on Steven MacLean by Gary Harkins results in a free kick. Callum Davidson takes the direct free kick.45:01
The referee gets the second half underway.45:00 +0:59 Half time
Half Time The referee calls an end to the first half.45:00 +0:32
Rowan Vine produces a right-footed shot from just outside the box that misses to the right of the goal.42:32
Rowan Vine takes a short corner.41:59
Effort from outside the penalty box by Cillian Sheridan goes wide left of the goal.41:05 Substitution
Substitution Mohamadou Sissoko joins the action as a substitute, replacing Lee Johnson.38:31
Shot from just outside the box by Rowan Vine misses to the left of the target.37:28
Headed effort from inside the area by Liam Craig misses to the right of the target.34:32 Booking
Booking Rowan Vine booked for unsporting behaviour.32:25
Murray Davidson takes a shot. Cameron Bell makes a save. Inswinging corner taken by Liam Craig, Murray Davidson challenges Cameron Bell unfairly and gives away a free kick. Cameron Bell takes the direct free kick.31:57
Borja Perez concedes a free kick for a foul on Callum Davidson. Frazer Wright takes the direct free kick.30:57
Assist by Gregory Tade.30:57 Goal scored
Goal! - Murray Davidson - Kilmarnock 0 - 1 St J'stone Goal scored by Murray Davidson from close in low into the middle of the goal. Kilmarnock 0-1 St Johnstone.29:14 Substitution
Substitution (St Johnstone) makes a substitution, with Rowan Vine coming on for Nigel Hasselbaink.28:10
The offside flag is raised against Callum Davidson. Cameron Bell restarts play with the free kick.27:52
Shot by Liam Craig. Save made by Cameron Bell.26:24
Liam Craig takes a shot. Save by Cameron Bell.24:11
James Fowler delivers the ball, save by Alan Mannus.20:48
Steven MacLean has an effort at goal from just outside the area which goes wide of the left-hand post.20:20
Outswinging corner taken from the left by-line by Liam Craig, Borja Perez makes a clearance.18:04
Foul by Gary Harkins on Murray Davidson, free kick awarded. Alan Mannus takes the free kick.14:57
The free kick is delivered left-footed by Jeroen Tesselaar from left wing, Foul by Cillian Sheridan on Frazer Wright, free kick awarded. Direct free kick taken by Alan Mannus.14:57 Booking
Booking Chris Millar is shown a yellow card for unsporting behaviour.14:53
Foul by Chris Millar on Cillian Sheridan, free kick awarded.14:32
Gregory Tade takes the chance to get an effort at goal. Save by Cameron Bell.13:47
Handball by Liam Craig. James Fowler takes the free kick.12:44
Steven MacLean takes a shot. Save by Cameron Bell.11:50
Cillian Sheridan concedes a free kick for a foul on David MacKay. Direct free kick taken by Steven Anderson.10:38
Jeroen Tesselaar fouled by Gregory Tade, the ref awards a free kick. Gary Harkins takes the free kick.10:05
Cillian Sheridan takes a shot. Save made by Alan Mannus.8:47
Jeroen Tesselaar challenges Steven MacLean unfairly and gives away a free kick. Free kick taken by Steven Anderson.6:46
Gary Harkins fouled by Nigel Hasselbaink, the ref awards a free kick. Cameron Bell takes the direct free kick.4:37 Dismissal
Dismissal The referee red cards Manuel Pascali for violent conduct.3:44
Foul by Manuel Pascali on Nigel Hasselbaink, free kick awarded. Direct free kick taken by David MacKay.1:51
Steven MacLean challenges Manuel Pascali unfairly and gives away a free kick. Michael Nelson takes the free kick.0:00
The game begins.
Live data and text provided by our data suppliers