Defender Craig Reid scored in the dying moments to give the visitors all three points in a thrilling end to the campaign.
The match appeared to be heading for a stalemate, which would have secured second spot for Aberdeen, when Motherwell snatched the points.
Keith Lasley launched a free-kick into the penalty area and the ball spun off the bar, before Reid scrambled his effort over the line.
The home side settled quickly and Jonny Hayes sent a shot from outside the box narrowly wide of the target after five minutes.
Aberdeen talisman Niall McGinn then hit a firm drive from the left side of the penalty area, but keeper Lee Hollis made a comfortable save.
Motherwell finally created a chance 12 minutes before the interval when Iain Vigurs fired a shot wide of the target.
Shaleum Logan, who scored a spectacular goal against Celtic last weekend, had a right-footed shot from outside the box blocked shortly before McGinn fired just wide.
At the other end Henri Anier forced Dons' goalkeeper Jamie Langfield into action as he got down at his post to make a save on 42 minutes.