Dagenham & Redbridge saw their hopes of a plum FA Cup third-round home tie against Premier League side Leicester shattered at Gillingham.
Captain Matt Robinson – released by the Foxes as a youngster – put Daggers ahead in their replay at Priestfield with a fine finish, but the home side scored with two headers from corners, before Harry Phipps saw red to compound the misery for Daryl McMahon’s men.
And after substitute George Saunders levelled for the 10 men, Hakeeb Adelakun lashed home a stunning winner in the final seconds of stoppage time to settle the outcome.
Less than two minutes had been played when Elliott Johnson seized on a poor back pass on the left and found Josh Walker, but his scuffed shot on the turn bobbled wide of the far post.
But Elliot Justham had to push a low drive from Lewis Walker behind at the other end moments later and Phipps blocked Elkan Baggott’s volley from the corner on the line.
Daggers took the lead on the quarter-hour mark when Phipps clipped the ball into the box for Walker to lay it off to skipper Robinson, whose controlled first-time shot beat the right hand of Jake Turner.
The hosts – with only six league goals all season and just one win in 14 matches in all competitions – got back on level terms on 26 minutes, though, as Johnson deflected David Tutonda’s dangerous cross behind for a corner and Indonesian international Baggott got up above Justham to head home.
Tutonda sent a right-footed shot high over the bar when the ball was cut back from the right, but Josh Hare sent a tempting low centre right across the face of the Gills goal and then saw a 25-yard drive saved by Turner at the end of the first half.
And Dom Jefferies produced a vital touch to head Myles Weston’s inswinging cross behind his own goal, as Robinson looked to profit in stoppage time.
Daggers picked up from where they had left off at the start of the second half, moving the ball around with the type of confidence befitting a side with a record of just two losses in 12 outings.
And Johnson made way for Saunders on 55 minutes as McMahon made his first change of the evening, with the substitute putting a good ball in from the left soon after, which Gills cleared.
Weston tried his luck from the right corner of the box on 63 minutes, with frost starting to form on the pitch as the temperature dropped, but he could not get enough bend on the ball and it flew beyond the far post.
Gills boss Neil Harris, an FA Cup finalist with Millwall in 2004, made a double substitution just past the hour, sending on Alex MacDonald and Scott Kashket – the injury-time hero at Victoria Road – for Ben Reeves and Jordan Green and the hosts began to enjoy some decent possesion of their own.
Daggers had a let-off when Walker was flagged offside after getting behind Manny Onarise and slotting past Justham, with Kashket poking a great close-range chance wide of the near post after a good run and cross by Adelakun.
There was another warning for the visitors when Onariase deflected a Walker shot behind, but German centre-back Max Ehmer headed home at the far post from the resulting corner from MacDonald to put Gills in front with 13 minutes to go.
McMahon replaced Sagaf with Jay Bird, but saw his side reduced to 10 men just moments later when Phipps caught Walker late and was shown a straight red card.
Remarkably, they got back on level terms on 84 minutes, though, when Bird flicked on a long kick from Justham and Saunders – having only recently returned to action from a broken leg – pounced on a weak header from Ehmer to skip around Turner and slot home.
Adelakun dragged a half-chance beyond the far post for the hosts with less than two minutes left, before Daggers saw Walker dance to the byline in stoppage time to win a last-gasp corner.
But Turner punched Saunders’ delivery from the left wing clear to set up a counter-attack that ended with Kashket finding Adelakun to lash home a left-footed shot with less than 30 seconds left on the clock.
Dagenham & Redbridge: Justham, Hare, Onariase, Phipps, Weston, Rance, Robinson, Sagaf (Bird 77), Johnson (Saunders 55), Walker, Morias. Unused subs: Mussa, McCallum, Zouma, Scott, Longe-King, Dixson, Franz.