Gearoid McKiernan's goal proved crucial as the Ulster county defied the odds for their first win of the campaign.
The shock victory was Cavan's first in the top division for 13 years.
Meanwhile, Monaghan are level with the leaders in Division One after a 2-17 to 1-13 win over pointless Roscommon who looked doomed to relegation.
Forwards Conor McManus and Jack McCarron did most of the damage, scoring 1-10 between them.
McCarron toe-poked in the first goal on 53 minutes with substitute Owen Duffy also finding the net.
Roscommon keeper Darren O'Malley made two vital saves in the first half to prevent earlier goals.
Tadgh O'Rourke scored a consolation goal for Roscommon but, having lost all five of their matches, Kevin McStay's side appear destined for the drop to Division Two.
Monaghan are in a four-way tie at the top of the division with Dublin, Donegal and Tyrone on seven points.
But it was Cavan's unexpected success which provided the story of the day in the top flight.
Mayo had looked in control, leading nine points to five heading into first-half stoppage-time.
But it all changed when McKiernan - the only Cavan player to score a league goal this year - smashed the ball past Mayo keeper David Clarke to reduce the gap to a single point.
The sides were level going into the last five minutes and points by Dara McVeety and Joe Dillon secured victory for the side rated 4-1 outsiders before throw-in.
Cavan pulled off a surprise 1-14 to 0-15 win over Mayo in Castlebar to give themselves a fighting chance of avoiding relegation from Division One.