Ansu Fati scored an extra-time winner as Barcelona scraped past third-tier Intercity 4-3 in the Copa del Rey after Oriol Soldevila's hat-trick.
A topsy-turvy tie saw the Blaugrana repeatedly frustrated by the minnows after Ronald Araujo's early effort had suggested a comfortable night for the 31-time winners.
That was certainly not the case, with Soldevila's hat-trick of equalisers sending the tie into extra time after Ousmane Dembele and Raphinha had each restored Barcelona's lead.
But Soldevila and Intercity could not repeat the feat a fourth time after Fati struck decisively in the 103rd minute.
A swift start for Xavi's side had seen Araujo head in Pablo Torre's corner with just four minutes on the clock, but the defender was soon required to clear off the line at the other end, and Intercity improved further after half-time.
A deserved equaliser followed just before the hour mark, with Vadik Murria nodding a corner down for Soldevila to fire past the helpless Inaki Pena.
The scores were only level for seven minutes as Dembele latched onto Gavi's pass to chip an effort over Gaizka Campos, but Intercity again fought back and Soldevila faced no challenge from Jordi Alba as he headed his second.
Alba redeemed himself with an assist for Raphinha at the other end, only for the winger to be brilliantly denied another by Campos, with Soldevila breaking from the subsequent corner to sensationally force extra time.
A fortuitous Barcelona fourth would prove enough, however, as Fati's deflected effort deceived Campos to send the visitors into the last 16.