Eoghan Ban Gallagher on the ball for Donegal. Photo Geraldine Diver
Mayo kicked the last three points to ensure survival in Division One of the Allianz League for a 21st year and send Donegal to Division Two for next season.
They were made fight all the way and Donegal will be kicking themselves that they didn't take two chances late on; Odhran MacNiallais was wide and Patrick McBrearty was short.
However, Donegal were not happy that the referee did not give them one last opportunity as Mayo delayed the Donegal kick-out and then when things were calmed, he sounded the final whistle.
Donegal had Patrick McBrearty back to give them a great boost while Ryan McHugh was ruled out because of delayed concussion.
Mayo were the dominant team in the opening ten minutes with the Donegal last line under pressure. They were on the board after 32 seconds with Andy Moran finishing a lightning move.
Frank McGlynn levelled for Donegal but it was all Mayo. Jason Doherty and Kevin McLoughlin pointed before a poor kick-out from Shaun Patton saw Moran send Diarmaid O'Connor through but Patton redeemed himself with a great save. The ball broke to Andy Moran who fisted a point. And on 10 minutes Moran got free inside when a Donegal defender slipped to fire over (he could have went for goal).
Trailing 0-5 to 0-1 it didn't look good for Donegal, but then there was a see-change. They hit the next seven points without response in a real purple patch. Ciaran Thompson started the run and Eoghan Ban Gallagher added another. Michael Murphy converted a 47m free before Jamie Brennan levelled scores.
Then up stepped Patrick McBrearty with a wonder point from near the sideline. Ban Gallagher added his second before McBrearty hit another from distance.
Conor Loftus got Mayo's first in 20 minutes after Andy Moran won a free but McBrearty had the final point of the half, a free from just inside the 45m line.
Half-time: Donegal 0-9, Mayo 0-6
The second half was tit for tat until the final five minutes. Donegal were three points in front, 0-13 to 0-10 at that stage, but they went defensive and Mayo, who looked devoid of ideas up to then, suddenly got the chances.
Conor Loftus, who hit five second half points, all from frees, got them within two and then Eoin O'Donoghue came forward from corner back to cut the deficit to one. With the momentum, Kevin McLoughlin hit the winner with 20 seconds left, and the referee did not allow Donegal another attack, blowing the whistle from the kick-out.
Scorers - Donegal: Patrick McBrearty 0-4,2f; Michael Murphy 0-2,1f; Jamie Brennan, Eoghan Ban Gallagher 0-2 each; Frank McGlynn, Ciaran Thompson, Odhran MacNiallais 0-1 each.
Mayo: Conor Loftus 0-6,5f; Andy Moran 0-3; Kevin McLoughlin 0-2; Jason Doherty, Eoin O'Donoghue 0-1 each.
DONEGAL: Shaun Patton; Paddy McGrath, Neil McGee, Eoghan Ban Gallagher; Frank McGlynn, Leo McLoone, Eamonn Doherty; Michael Murphy, Hugh McFadden; Ciaran Thompson, Odhran MacNiallais, Paul Brennan; Niall O'Donnell, Patrick McBrearty, Jamie Brennan. Subs, Mark McHugh for O'Donnell 45; Caolan Ward for McGee 57; Conor Morrison for McGrath; Stephen McBrearty for Thompson both 58; Caolan Ward for McGee 59; Cian Mulligan for Brennan 67.
MAYO: David Clarke; Caolan Crowe, David Drake, Eoin O'Donoghue; Colm Boyle, Stephen Coen, Paddy Durcan; Seamus O'Shea, Tom Parsons; Kevin McLoughlin, Aidan O'Shea, Diarmuid O'Connor; Jason Doherty, Andy Moran, Conor Loftus. Subs., Michael Hall for Drake 64; Fergal Boland for S O Shea 65; Barry Moran for Parson 67.
REFEREE: Anthony Nolan (Wicklow)