Underdogs Cavan caused a huge upset with a victory over Mayo in Castlebar which has kept alive their hopes of staying in Division 1.

For Mayo, it is a result which has brought their own safety very much into question.

In the end Cavan had two points to spare and were full value for their victory.

Indeed, they could have won by more had a late goal from Dara McVeety not been harshly ruled out.

A goal from outstanding midfielder Gearoid McKiernan right on the stroke of half-time was the catalyst for a strong second half from Cavan.

They were four points down when McKiernan got forward from midfield to finish well past David Clarke.

Mayo had played the better football to that point without setting the world on fire. Andy Moran, Conor O'Shea and Danny Kirby kicked a brace each but, even with the wind, Mayo were struggling to get into good scoring positions and the goal put a very different complexion on matters at the interval.

Cavan came out for the second half in determined fashion and with the likes of McVeety and Tomás Corr supplementing McKiernan's work, they got through the Mayo defence much easier than Mayo could manage at the other end.

Cavan got bodies back and when they turned over Mayo, they broke quickly and decisively.

They took the lead for the first time in the 42nd minute but the lead did see-saw for the remainder of the game.

Some fine scores from Danny Kirby - who kicked four points from midfield - and Lee Keegan kept Mayo in the game and substitute Shane Nally had Stephen Rochford's men in front on 57 minutes.

It was a test of Cavan's belief and they answered in style. Mayo would not score again and points from McKiernan, McVeety and sub' John McCutcheon saw them home.

They go into their last two games against Kerry and Roscommon needing more points but still very much alive.

Mayo, after a very disappointing defeat to Dublin, have a lot of questions now to answer in their final two games against Tyrone and Donegal. They will need one win to be assured of safety.

Cavan: R Galligan; K Brady, F Reilly, R Dunne (0-1); D McVeety (0-3), K Clarke, C Moynagh; G McKiernan (1-5, 0-3f), T Corr (0-2); M Reilly (0-1), N Murray, N Clerkin; G Smith, C Madden (0-1), S Johnston.

Subs: C Mackey for Johnston (44), S Murray for N Murray (60), C Brady for Clerkin (60), J McCutcheon (0-1) for Madden (63), P O'Connor for Corr (70).

Mayo: D Clarke; P Durcan, B Harrison, K Higgins; C Boyle, D Vaughan, L Keegan (0-2), T Parsons, D Kirby (0-4); F Boland (0-1), C O'Connor, C O'Shea (0-2); K McLoughlin (0-1, f), A Moran (0-3), C Loftus.

Subs: S Coen for Vaughan (53), S Nally (0-1) for Boland (55), E Regan for Loftus (60), N Douglas for O'Shea (65), J Gibbons for Parsons (70).

Referee: Anthony Nolan (Wicklow).