Armagh qualified for their first TG4 All-Ireland Senior semi-final since 2015 with two Aimee Mackin goals and one each from Kelly Mallon and Catherine Marley denying Mayo a return to the knockout stages.
Substitute Fiona Doherty hit the net for Mayo 13 minutes after the break, which levelled the scores, but points from Aoife McCoy and Mallon, as well as Marley's goal in the final minute sees Armagh into a semi-final against defending champions Dublin.
While the winning margin was five points in the end, the teams were level on seven occasions and Mayo were in with a chance of victory for 55 minutes.
Grace Kelly was outstanding for Mayo and she kicked her side into the lead after four minutes – the first of four first-half points she would land from open play.
Aimee Mackin was out in front to kick her side level two minutes later, and when she repeated the feat in the seventh and eighth minutes her side was one ahead, and it was clear she was in top form once more.
At the other end Sarah Rowe was followed everywhere by Tiarna Grimes, but she escaped her clutches in the 11th minute to level matters, but seconds later Armagh kicked on when Mallon finished off a good move down the left flank with a smart, low finish.
Armagh might have expected to build on that goal, but instead Mayo took over totally for 15 minutes. Sinead Cafferky started them on a run of seven straight points with two of her own, while Kelly and Deirdre Doherty all weighed in to put Mayo 0-10 to 1-3 clear.
Peter Leahy's plan was being executed beautifully with Ciara McManamon and Dayna Finn playing well at the back, but in the blink of an eye Armagh turned the game in their favour again. A Mallon free was followed by a splendid Aimee Mackin point from the right that sailed over off the outside of her boot.
And two minutes from the break Blaithín Mackin sent an accurate diagonal ball into her sister, and Aimee Mackin fired to the net off the ground, which levelled the scores.
But by the half-time whistle Armagh were two points clear when the Mackin sisters added a point each to make it 2-07 to 0-11.
Leahy introduced Fiona Doherty and Mary McHale at half-time, and his changes had an immediate impact. The duo linked up for a McHale score four minutes after the break, but when Mallon sent Aimee Mackin in for her second goal Armagh led by four points.
McHale scored her second point for Mayo, who continued to battle on, and when Cafferky broke a throw ball into Doherty’s path and she scored from a tight angle, Mayo were level again, 1-13 to 3-7.
With the game in the balance McCoy and Mallon kicked points from play, and even though Deirdre and Fiona Doherty kept Mayo in touch, Armagh made sure of the win when Catherine Marley hit the net in the final minute.
Armagh: A Carr; S Marley, C McCambridge, S Grey; T Grimes, B Mackin (0-01), G Ferguson; N Coleman, A Bellew; C Marley (1-00), A McCoy (0-01), E Lavery; C O’Hanlon, K Mallon (1-03, 1f), A Mackin (2-07, 2f).
Subs: T McVeigh for Grey 55.
Mayo: L Brennan; D Caldwell, R Durkin, Ciara McManamon; É Ronayne, D Finn, E Brennan; A Gilroy (0-01), Clodagh McManamon; G Kelly (0-04), S Cafferky (0-02), S Rowe (0-02); M Reilly, R Kearns, D Doherty (0-04, 2f).
Subs: F Doherty (1-01) for Clodagh McManamon h-t, M McHale (0-02) for Reilly h-t, K Sullivan for Ciara McManamon 40, C Whyte for Kelly 46.
Referee: Jonathan Murphy (Carlow).