Madrid - Barcelona were spared an embarrassing night in Ibiza on Wednesday as Antoine Griezmann scored twice, including a 94th-minute winner in a 2-1 victory to send them through to the next round of the Copa del Rey.
Ibiza play in Segunda B, Spain's third tier, and sit 44 places below the reigning La Liga champions but an extraordinary upset looked on the cards when Javi Perez gave the hosts an early lead at Can Misses.
But with Lionel Messi rested and not even on the bench, Griezmann filled the void by finding an equaliser in the second half and then scoring the injury-time winner to break Ibiza hearts.
Griezmann's double was particularly important for new coach Quique Setien, who enjoyed a 1-0 victory in his first game against Granada on Sunday but could hardly afford a loss of this magnitude so early in his tenure.
Despite the tight scoreline, the win over Granada was hailed as a success, a return to the passing style and attacking philosophy of Barcelona that had been lost under Ernesto Valverde.
Their 83 per cent possession was the highest in La Liga since Pep Guardiola's side in 2011 but for all the dominance of the ball, there was a lack of cutting edge, a problem that was again evident against Ibiza.
They restricted their star-studded opponents to one shot in the first half, Barcelona's lowest in any game they have played this season.
With a trip to Valencia to come in La Liga on Saturday, Setien left Messi, Sergio Busquets and Gerard Pique not only out of the starting line-up but the squad too.
Youngsters like Ansu Fati, Riqui Puig and Carles Perez all started while Griezmann was left to lead the attack in the absence of Messi and the injured Luis Suarez.
Barcelona's dominance against Granada was to some extent aided by their opponents sitting deep but instead, Ibiza were at them from the off, closing the gaps and snapping at their heels whenever they could.
Every Barca missed pass was cheered, every Ibiza challenge applauded but if the home side's aim was to contain, they went one better by taking the lead in the ninth minute.
Puig was at fault, caught napping by Javi Perez, who nipped in to meet the cross from the left and finished smartly past Neto.
Barca responded with patience and passing in the hope of exerting some control. But every time Ibiza got the ball their pace and energy looked the more likely ingredients for a goal.
Twice they almost added a second as Angel Rodado scored after bundling through Clement Lenglet but too enthusiastically, with the goal chalked off. Then Rai Nascimento hit the post after being played in by Javi Lara and Rodado went close with the rebound but Neto pushed the shot over the crossbar.
Perhaps Ibiza ran out of steam because their pressing lost some intensity in the second half. Jordi Alba and Arthur Melo came on for Carles Perez and the struggling Puig, and in the 72nd minute, Griezmann equalised.
Frenkie de Jong's reverse pass was perfectly weighted, with Griezmann able to hit first time on the turn past German Parreno.
Ibiza's energy and belief had almost run out and just as they looked set for extra-time, Griezmann struck again. Alba slid him through down the left and his finish flew across Parreno and found the far corner.