Dublin 2-12 Mayo 1-15
Andy Moran emerged as Mayo's super substitute at Croke Park with a dramatic injury-time equaliser that capped an incredible comeback, securing All-Ireland football semi-final replay.
The five-in-a-row Connacht champions looked down and out when they trailed by six with 63 minutes on the clock but staged a thrilling recovery in the closing minutes to force a second date.
Veteran Moran was their inspiration as his first point began a scoring blitz of 1-3 without reply from the westerners and he also booted that crucial leveller at the end of the frenetic period.
The goal came from the boot of Cillian O'Connor who expertly converted a 69th minute penalty following a foul on Colm Boyle and finished with 1-9 in total.
The result means Mayo will contest a replay at this stage for the second successive year though Dublin will kick themselves for not securing a September 20 final clash with Kerry.
Jim Gavin's side got the perfect start when Diarmuid Connolly netted after just five minutes but couldn't shake off Mayo despite leading throughout the game.
Connolly was eventually red carded in the 74th minute for an incident involving Lee Keegan, while Dubs midfielders Michael Darragh Macauley and Denis Bastick were both black carded in the second-half.
All the talk beforehand was of Mayo's danger man, full-forward Aidan O'Shea, and Mayo were unashamed about directing as many of their early attacks as possible towards the big Breaffy man.
It met with limited success. O'Shea was fouled for two frees that Cillian O'Connor converted. But he was also twice penalised for over carrying as Dublin got three and four men around him.
Mayo appeared to lack other options in attack and were grateful for O'Connor's free-taking ability as he scored all but one of their first-half tally from frees.
Dublin ultimately took a 1-7 to 0-7 advantage into the interval and were good value for it, Connolly's early penalty conversion separating them.
Paul Flynn was the player who earned the spot kick after being bundled over by Jason Doherty and Connolly shot low and left to the corner of the Mayo net.
Flynn's form has been patchy for Dublin all summer but he enjoyed a strong first-half, playing excellent diagonal passes that led to points for Paddy Andrews and Ciaran Kilkenny.
Dublin were 1-3 to 0-1 clear at one stage early on and though Mayo soon found their range, almost principally from frees, the title favourites were generally at least three clear.
Kilkenny was influential, scoring three early points and showing his full array of skills as he converted with his fist, his right foot and his left foot.
Macauley started at midfield in place of Bastick having been dropped for the quarter-final against Fermanagh and got through plenty of good work.
But Macauley's afternoon was over in the 50th minute when he received a black card for pulling down Keith Higgins.
Mayo briefly got the deficit down to one point in the third quarter with points from Cillian and Diarmuid O'Connor, 1-7 to 0-9.
But Dublin found their best form in the following 10 minutes or so to move decisively clear. Kevin McManamon's 58th minute goal appeared a game-changing score as he capitalised on great work by Jack McCaffrey.
Wing-back McCaffrey fed Brian Fenton after a wonderful solo run and though Fenton's shot was blocked, McManamon followed up with the crucial strike.
Bernard and sub Alan Brogan followed up with fine points for Dublin before a McCaffrey point that left the five-in-a-row Leinster champions 2-12 to 0-11 clear.
But they couldn't hold on as Mayo staged a truly memorable recovery to keep alive their Championship ambitions.
Dublin: S Cluxton; R O'Carroll, P McMahon, J Cooper; J McCarthy, C O'Sullivan, J McCaffrey (0-01); B Fenton, MD Macauley; P Flynn, P Andrews (0-02), C Kilkenny (0-03); D Rock, D Connolly (1-02, 1-00 pen, 0-01f), B Brogan (0-02).
Subs: M Fitzsimons for O'Carroll (blood), K McManamon (1-01) for Rock, J Small for Cooper, D Bastick for Macauley (black card), A Brogan (0-01) for Andrews, T Brady for Fenton, E Lowndes for Bastick (black card).
Mayo: D Clarke; C Barrett, G Cafferkey, K Higgins (0-01); D Vaughan, L Keegan (0-01), C Boyle; T Parsons, S O'Shea; D Drake, J Doherty, D O'Connor (0-01); K McLoughlin, A O'Shea, C O'Connor (1-09, 0-08f, 1-00 pen, 0-01 45).
Subs: P Durcan for Vaughan, A Moran (0-02) for Drake, A Freeman (0-01) for Doherty, B Moran for S O'Shea, M Sweeney for D O'Connor.
Referee: J McQuillan (Cavan)