Two late frees from Cillian O'Connor secured victory for Mayo at Páirc Ui Caoimh 0-11 to 0-10, but more importantly they booked a place in the divisional semi-final.

Cork, who also avoided relegation, looked set to cruise to a facile victory by 0-8 to 0-2 five minutes from half-time, but Mayo rallied before the break to trail by just three at the turnaround.

And the westerners, who will now face Dublin next Sunday, dominated the second-half and with O'Connor and Kevin McLoughlin kicking vital scores, James Horan's men took their third win of the campaign.  

Despite struggling as the first-half went on, Mayo started the game very brightly and a lovely point from Kevin McLoughlin off the outside of his boot gave them the lead in the first minute.

But for the next 27 minutes the home side dominated entirely as eye-catching points from Aidan Walsh and the excellent Fintan Goold got them up and running.

After getting himself off the mark with a good score from the left, Daniel Goulding should have punished Mayo even more, but he sent his tenth minute close range free wide.

But those early wides looked like they wouldn’t matter as seven points in a row including another booming effort from Goold, saw Cork open out a 0-7 to 0-1 lead by the 23rd minute.

However, as half-time approached Mayo recovered and Michael Conroy, Aidan O'Shea and Alan Freeman scores before the break to reduce the deficit to 0-8 to 0-5 at the break.

Donal Vaughan pointed immediately after the restart to get Mayo off to a great start and after Goold kicked his third point from play to renew the half-time lead, Mayo began to show the form that saw them reach last year's All-Ireland final.

O'Connor kicked his first free after a foul on Michael Boyle in the 47th minute, before McLoughlin added a free and a point from play to draw Mayo level five minutes later.

Goulding edged Cork ahead with a free as the intensity was upped noticeably, but with their division one status hanging the balance Mayo looked the hungrier for the battle.

And that proved to be the case as O'Connor landed two huge frees from each touchline to give Mayo the lead with six minutes remaining, as they held on to secure the win and claim a spot in the semi-finals.

Mayo: D Clarke; K Keane, G Cafferkey, S McHale; L Keegan, D Vaughan (0-01), C Boyle; J Gibbons, S O'Shea; K McLoughlin (0-04, 0-02f), A O'Shea (0-01), C Carolan; C O'Connor (0-03, 0-03f), A Freeman (0-01), M Conroy (0-01).

Subs: E Varley for Conroy (42 mins), R Feeney for Carolan (47 mins), J Doherty for Freeman (57 mins), D Coen for Varley (57 blood), C Barrett for McHale (63), E Regan for O'Connor (72 mins),

Cork: K O'Halloran; J McLoughlin, J O'Sullivan, M Shields; P Kissane (0-01), N O'Leary, T Clancy; A Walsh (0-01), G Canty; M Collins (0-01, 0-01f), F Goold (0-03), A O'Sullivan; D Goulding (0-04, 0-03f), B O'Driscoll, P Kerrigan.

Subs: J Loughrey for O'Leary (27-35 mins blood), P O'Neill for A O'Sullivan (51 mins), J Loughrey for McLoughlin (51 mins),

Referee: Maurice Deegan (Laois).