Cristhian Stuani came off the bench to deny Sky Bet League One Oxford a place in the draw for the FA Cup quarter-finals as Premier League Middlesbrough survived a major scare to triumph 3-2 at the Riverside Stadium.
Aitor Karanka's men looked to be heading for the Kassam Stadium for a replay after squandering a 2-0 lead inside a single madcap second-half minute, but Uruguay international Stuani came to the rescue with an 86th-minute winner to secure a place in the last eight for the first time since 2009.
Grant Leadbitter's penalty and January signing Rudy Gestede's first goal for the club had given Boro a commanding half-time lead, but Chris Maguire's superb free-kick and Antonio Martinez's equaliser just seconds later left the result in the melting pot.
Oxford might have taken an early lead when goalkeeper Simon Eastwood saw his scuffed clearance fall to a yellow, rather than a red, shirt and when Ryan Ledson helped the ball forward, Martinez turned central defender Bernardo Espinosa all too easily, but could not beat Brad Guzan with his shot.
Shaken from their slumbers, Boro responded in determined fashion with Viktor Fischer and Adama Traore prospering out wide and Leadbitter and Stewart Downing linking midfield with attack.
Gestede probably should have opening the scoring with a free header from Leadbitter's sixth-minute free-kick, but only found Eastwood's arms, while Leadbitter clipped the top of the crossbar with a delicately chipped effort three minutes later.
The home side finally made the pressure tell with 26 minutes gone after Maguire sent Downing tumbling inside the box as he ran on to Leadbitter's through-ball.
It was the skipper who take charge from the penalty spot and smashed the ball high into the roof of Eastwood's net to open the scoring.
Maguire thought he had made amends within six minutes when his shot eluded keeper Brad Guzan, although referee Andre Marriner chalked off his effort for a foul by Kane Hemmings on Bernardo.
The visitors' fortunes took a further turn for the worse when Traore turned Fabio's cross back across goal and Gestede leapt to volley acrobatically past Eastwood in the 34th minute.
Boro looked to kill off the game quickly after the restart with Downing firing wide from distance before Fischer prompted a vital block by defender Cheyenne Dunkley as he attempted to convert Traore's near-post cross.
But Daniel Ayala had to be in the right place at the right time to turn away John Lundstram's inviting 59th-minute cross with Martinez waiting to pounce behind him, and there was better to come from his side.
Traore was penalised for a clumsy challenge on Phil Edwards 20 yards out and Maguire curled a delicious 64th-minute free-kick past Guzan's despairing dive, and they were not finished there.
Seconds later, Guzan could only parry Maguire's low strike and Martinez thumped the rebound into the unguarded net to send the 3,376 travelling fans among a crowd of 28,198 into raptures.
Both sides pressed for a winner amid a tense conclusion, and there were just four minutes remaining when Stuani prodded home Fabio's cross from point-blank range to break Oxford hearts.