Mayo breathed a sigh of relief as they stumbled to a 3-15 to 1-14 victory over Westmeath in this entertaining All-Ireland SFC qualifier.
The game looked to be over after 30 minutes when Westmeath trialled by 2-09 to 0-04 after goals from Jason Doherty and a Cillian O'Connor penalty.
A defensive Westmeath looked dead and buried but a James Dolan goal just before the break gave the Lake County some hope.
The second half was the Leinster side bring the game to Mayo, and they closed the gap to three points before a late surge saw Mayo over the line against Westmeath who finished the match with 14 men after Denis Corroon received a second yellow card in the 63rd minute.
Once the minute's silence for former Westmeath footballer Liam Mullen and the National Anthem were out of the way the action got underway.
Three minutes were on the clock before the opening score came and it was Westmeath's John Heslin who found the target from a 30 metre free.
Heslin then missed one before Mayo got on the scoresheet with a free of their own as Evan Regan taps over from the 20 metre line.
Westmeath edged back in from a second Heslin free, but Mayo and in particular Andy Moran came into the game more.
First, Moran got his first score of the game with a fine turn and shot, before the same player found Cillian O'Connor who pointed from play.
Moran himself was then fouled and Regan kicked his second free from close in, before Moran made it four points in a row after a good run by Keith Higgins.
Westmeath were very much out of sorts and they were not finding their man with the ball, but they earned a free under the Cusack Stand, which for a right-footer was a difficult angle, but Heslin was up to the challenge as he kicked over the bar from the Hill 16 end.
From the kick out, Mayo worked the ball forward and Donal Vaughan found Jason Doherty who slotted low past Darren Quinn.
This lifted Mayo, while Westmeath heads dropped somewhat as Patrick Durcan added a point from long range.
Heslin responded with a good effort from play, but Mayo stepped up another gear and points from O'Connor, Regan and Moran were followed up by a converted penalty by O'Connor.
Quinn had dealt with a high ball but for reasons only known to himself, he managed to over carry the ball and referee Rory Hickey rightly so awarded the penalty. That made the score 2-09 to 0-04 with 30 minutes played.
However, a brilliant effort by James Dolan who surged forward and fired low to the net, lifted Westmeath and from a poor kick out, they should have had a second as Kieran Martin slipped when one on one with David Clarke.
Westmeath did earn a free from that play and Heslin tapped over for his fifth point of the half.
Westmeath threw off the shackles in the second half and hit four answered points through Dolan, Frank Boyle and two Heslin free to make it 2-10 to 1-09 by the 40th minute.
A point from play by Doherty settled Mayo a bit in the 44th minute, and six minutes elapsed before the next score of the game.
Again it was Heslin as he pointed from play after good work by Jamie Gonoud. This was cancelled after another six-minute lull as Keith Higgins scored from distance.
From the kick out Kieran Martin made it 2-13 to 1-11 as Westmeath grew in stature. They were let off the hook a minute later when O'Connor managed to play himself in and his shot came back off the upright.
Heslin scored his 12th point of the game with another free and then the crossbar came to Westmeath's rescue as O'Connor's free from 45 metres was flicked on to the bar by Aidan O'Shea.
A Vaughan point made it 2-14 to 1-13 with seven minutes remaining, and Corroon saw his second yellow.
Heslin got Westmeath's last score in the 68th minute before O'Connor free and an Aidan O'Shea goal closed out the game.
Mayo - D Clarke; B Harrison, K Keane, K Higgins (0-1); L Keegan, C Boyle, P Durcan (0-1); S O'Shea, D Vaughan (0-1); K McLoughlin (0-1), A O'Shea (1-0), J Doherty (1-1); E Regan (0-3, 2f), A Moran (0-2), C O'Connor (1-5, 1-0pen, 0-2f). Subs: B Moran for C Boyle, A Dillon for E Regan, C O'Shea for J Doherty, A Freeman for A Moran, C Barrett for L Keegan, T Parsons for S O'Shea.
Westmeath - D Quinn; K Maguire, F Boyle (0-1), K Daly; J Gonoud, D Lynch, J Dolan (1-1); A Stone, G Egan; J Egan, P Sharry, K Martin (0-2); C McCormack, J Heslin (0-10, 7f), J Connellan. Subs: D Corroon for A Stone, D Daly for D Lynch, D McNicholas for J Connellan, D Conway for C McCormack.
Referee - R Hickey.Tweet