Ansu Fati snatched an extra-time winner for Barcelona in a thrilling 4-3 victory over third-tier Intercity in the Spanish Cup round of 32 on Wednesday.
The minnows from Alicante nearly embarrassed Barcelona with former La Masia youth player Oriol Soldevila scoring a superb hat-trick to force extra-time, before Fati's deflected strike settled the tie.
Ronald Araujo headed home after just four minutes from youngster Pablo Torre's corner, making it look like Barca would breeze into the last 16.
The Uruguayan defender made a lively comeback from the thigh injury which kept him from starting for his country at the World Cup, also clearing an effort off the line.
Ferran Torres and Ousmane Dembele spurned opportunities for the visitors before Intercity struck a shock equaliser, with Soldevila netting from close range after the ball was nodded into his path from a corner.
Dembele executed a fine chip to put Barcelona back in front when he was sent through in the 66th minute.
Intercity levelled again when Soldevila produced a fine header to beat Inaki Pena but Raphinha stroked home Jordi Alba's low cross to restore Barcelona's lead.
However Soldevila completed a remarkable hat-trick against his former side after a Marcos Alonso slip-up to force extra-time.
Substitute Fati came close at the start of the additional period and then fired Barcelona ahead with a deflected strike which looped home in the 104th minute, and it proved decisive.
"It was the magic of the cup," Araujo told Movistar.
"It will serve us to learn from, the cup is like this, we know that."
Elsewhere Atletico Madrid earned a 2-0 win at second-tier Real Oviedo with goals from Marcos Llorente and talented youngster Pablo Barrios, while Sevilla also racked up a big win.
Jorge Sampaoli's side, struggling in La Liga, thrashed Linares 5-0, including a hat-trick for Moroccan World Cup hero Youssef En-Nesyri.
Mateu Lahoz's controversial refereeing in Barcelona's draw with Espanyol in La Liga on Saturday made headlines, and he continued in the same vein by sending off Sampaoli for dissent early in the first half.
Second division Alaves won 1-0 against La Liga side Real Valladolid, who had Zouhair Feddal dismissed in the first half to give themselves an uphill struggle.
Real Mallorca needed extra-time to beat Pontevedra 2-0, while Real Sociedad progressed to the last 16 with a 1-0 win at UD Logrones.