After getting back on level terms with normal time almost up, Wicklow snatched victory deep into stoppage time at Pearse Park on Saturday thanks to points from Paul Cunningham and Cathal McNicholas.
It was hard to take for Longford, who looked likely winners when firing home two goals in the space of a minute midway through the first half after Wicklow forward Darren Hayden had planted a cracking shot in the roof of the Longford net.
That goal left the visitors 1-1 to 0-2 ahead but Longford hit back to regain the lead when Philip Dobson hit the target in the 15th minute and they grabbed a second goal came moments later when Padraig Gill found the net from a tight angle.
Longford led 2-3 to 1-3 at the break and, while Wicklow narrowed the gap with a point from Donie Fitzgerald in the early stages of the second half, the home side appeared to have consolidated their grip on the game with a further brace of scores from Dobson and Denis McGoldrick.
Inspired by Ciaran Walsh -- who fired over four points on the trot -- Wicklow were soon all square but Dobson slotted over to put Longford back in front after 53 minutes.
Anthony McLoughlin equalised for Wicklow, and two injury-time scores from Cunningham, and McNicholas sealed the win to earn a home clash against Laois in the quarter-final on March 1.
Scorers -- Wicklow: C Walsh (4f) 0-6, D Hayden 1-1, D Fitzgerald, A McLoughlin, P Cunningham, C McNicholas ('45') 0-1, each. Longford: P Dobson 1-3, P Gill 1-0, W Crawford, G Dennigan (f), D McGoldrick 0-1, each.
LONGFORD -- C Garvey; G Farrell, K Diffley, A Quinn; CP Smyth, D Faughnan, J Sheridan; G Dennigan, M Brady; P Gill, D McGoldrick, S Kiernan; JJ Matthews, W Crawford, P Dobson. Subs: F Battrim for CP Smyth (30 mins); T Gallagher for M Brady ( 35 mins); S Henry for S Kiernan (43 mins); D McElligott for D McGoldrick (56 mins).
WICKLOW -- R Phelan; C O'Neill, B McGarr, C Doyle; S Metcalfe, B Osbourne, A McLoughlin; B Harmon, C McNicholas; S Carthy, D Fitzgerald, D Hayden; C Walsh, D Siney, P Cunningham. Subs: S Tobin for S Carthy (27 mins); C Coogan for B McGarr (ht); C Smullen for S Metcalfe (53 mins).
Ref -- E Kinsella (Laois).