Match ends, St. Mirren 2, Motherwell 1.
Motherwell will require success in the play-offs if they are to secure their Premiership status for next season.
A stoppage-time Stephen Mallan goal gave already relegated St Mirren victory in their penultimate top-flight fixture for a year at least.
Substitute John Sutton had given Motherwell the lead with a penalty.
But a Jason Naismith effort came off Motherwell's Mark O'Brien before nestling in the net and Mallan's goal consigned Well to second bottom place.
Before the late goal, Motherwell had striker Scott McDonald controversially sent off for violent conduct after a challenge with Thomas Reilly.
Ian Baraclough's Well will face Hibernian, Queen of the South or Rangers over two legs in the Scottish Premiership play-off final.
St Mirren had the opening chance when Sean Kelly was left unmarked at the back post at Mallan's free-kick but the defender's shot from the edge of the six-yard box was wide.
A huge travelling away support had arrived in Paisley to get behind their side but despite their backing, Motherwell had an air of tension in their early play.
As the weather deteriorated into a rain and hale storm, Alan Gow burst clear of the Well defence and with only goalkeeper George Long to beat slotted past the post.
At the other end, McDonald and Marvin Johnson combined to set up set up Erwin but the big striker's shot was turned to safety by Kello.
Motherwell's target of having to match or better the results of Ross County and Kilmarnock seemed to be having an adverse impact on their play as they looked to take the battle to avoid the play off spot to the last week of the season.
James Dayton rattled a shot towards George Long's goal that the keeper saved and Erwin and then McDonald headed just wide for Motherwell.
Gow was carried off on a stretcher after being clattered by Stephen McManus, who was booked for the challenge.
St Mirren should have taken the lead when substitutes Lewis Morgan and Kieran Sadlier along with Dayton peppered the Motherwell goal with a series of shots in a frantic sequence. However, the visitors somehow managed to keep their goal intact.
And when Reilly was judged to have fouled Erwin inside the box Motherwell got the breakthrough from the penalty spot.
Sutton, only on the pitch seven minutes as a replacement for Marvin Johnson, scored from the 12-yard mark.
The lead was short lived as Naismith's effort combined with the inability of Long and O'Brien to keep the ball out saw the Paisley side pull level.
In the final minute of regulation time, McDonald was dismissed by referee Brian Colvin after he seemed to catch Reilly with his arm in an aerial challenge.
The drama did not end there and in the seventh minute of added time Mallan blasted home the winner from 25 yards.
- 8GowSubstituted forMorganat 71'minutes
- 11WyldeSubstituted forSadlierat 65'minutes
- 9ThompsonSubstituted forArquinat 87'minutes
- 15O'BrienBooked at 41mins
- 6McManusBooked at 67mins
- 47GrantSubstituted forAinsworthat 59'minutes
- 14LasleyBooked at 56mins
- 48PearsonBooked at 90mins
- 24JohnsonSubstituted forSuttonat 69'minutes
- 77McDonaldBooked at 90mins
- Brian Colvin
- Shots on Target
Second Half ends, St. Mirren 2, Motherwell 1.
Yoann Arquin (St. Mirren) wins a free kick on the right wing.
Foul by Stephen Pearson (Motherwell).
Stephen Pearson (Motherwell) is shown the yellow card.
Goal! St. Mirren 2, Motherwell 1. Stephen Mallan (St. Mirren) right footed shot from outside the box to the top left corner. Assisted by Kieran Sadlier.
Sean Kelly (St. Mirren) wins a free kick on the left wing.
Foul by Lee Erwin (Motherwell).
Attempt missed. Thomas Reilly (St. Mirren) left footed shot from outside the box is close, but misses to the left.
Corner, St. Mirren. Conceded by Stephen McManus.
Thomas Reilly (St. Mirren) wins a free kick in the defensive half.
Foul by Scott McDonald (Motherwell).
Scott McDonald (Motherwell) is shown the red card for a bad foul.
Corner, St. Mirren. Conceded by Simon Ramsden.
Substitution, St. Mirren. Yoann Arquin replaces Steven Thompson.
Attempt missed. Stephen Mallan (St. Mirren) right footed shot from outside the box is just a bit too high.
Goal! St. Mirren 1, Motherwell 1. Jason Naismith (St. Mirren) right footed shot from a difficult angle on the right to the bottom left corner.
Foul by Lewis Morgan (St. Mirren).
Scott McDonald (Motherwell) wins a free kick in the defensive half.
Foul by James Dayton (St. Mirren).