Leitrim tested Mayo's Connacht championship mettle to the hilt at Carrick-on-Shannon before slipping to a 1-10 to 1-09 defeat.
Mickey Moran's men had the fright of their lives as they were held scoreless for the closing 26 minutes but hung on in to set up a provincial final against defending champions Galway.
Mayo led 1-07 to 0-04 at the interval and seemed to be coasting through to next month's decider. The hard-running Ger Brady slammed home their goal in the 31st-minute.
A Conor Mortimer point pushed Mayo eight clear, but incredibly they were held scoreless for the remainder of the match. Midfielder Pat Harte was sent off for his second bookable offence, then Leitrim centre-fielder Christy Carroll netted.
A late Michael Foley point put the minimum between the sides, but Mayo still squeezed through.
Leitrim were dealt a blow before the throw-in when full-forward Declan Maxwell was forced to cry off the team due to the knee ligament injury that has been plaguing him since last month. Donal Brennan came in to deputise.
Scores from Alan Dillon (free) and Mortimer saw Mayo on top in the early stages, with three wides from Leitrim seemingly offering them little hope for the 70 minutes ahead.
But backed by a vocal home support, Dessie Dolan snr's side were back level at 0-03 apiece by the midpoint of the half. Shane and Michael Foley and David McHugh replied with good points.
Mortimer, Ciaran McDonald and Harte struck back for Mayo with the Leitrim forwards struggling - their wides tally was up at five by the 20-minute mark. Darren Duignan sliced over a neat point on 22 minutes but that proved to be Leitrim's last score of the half.
Despite having his shot half-blocked, Brady's goal effort squeezed past Leitrim stopper Cathal McCrann to give Mayo some breathing space. Mortimer followed up with his third point of the half as the visitors ended it six points clear.
Points from Kilcoyne, McDonald and Mortimer swamped an effort from Ciaran Duignan early in the second half as Moran's charges went 1-10 to 0-05 in front.
However Harte's dismissal and Carroll's goal at the end of the third quarter put the cat amongst the pigeons. Leitrim, the last team into championship action this year, looked set to pull off a shock win - only their fourth success in 23 championship meetings with Mayo.
After a Colin Regan point, the home side were further boosted when the talismanic Maxwell made an appearance onto the field. Two further points from Foley and one from Brennan made it a one-point game - 1-10 to 1-09.
Some poor shooting and decision-making just let the hosts down in the final minutes. There were four additional minutes of injury-time but neither side could add to their tally and Mayo progressed but with much work to do.
Leitrim: C McCann; D Reynolds (capt), J McKeon, M McGuinness; D McHugh (0-01), B McWeeney, S Foley (0-01); G McCloskey, C Carroll (1-00); B Prior, M Foley (0-3 (3f)), C Regan (0-01); D Duignan (0-01), D Brennan (0-01), C Duignan (0-01 (1f)).
Subs used: M Greene for D McHugh (half time), J Goldrick for D Duignan, D Maxwell for C Duignan (both 61 mins), F Holohan for S Foley (69), D Beck for Regan (70).
Mayo: J Healy; D Geraghty, L O'Malley, P Higgins; D Heaney (capt), J Nallen, P Gardiner; R McGarrity, P Harte (0-01); BJ Padden, G Brady (1-00), A Dillion; K McDonald (0-03), C Mortimer (0-04 (2f)), Moran (0-01).
Subs used: A Kilcoyne (0-01 (1f)) for Dillon (half time), P Kelly for Heaney (56 mins), J Gill for Kilcoyne (65), B Moran for G Brady (70).
Referee: Tomas Quigley (Dublin)