Lionel Messi marked his return from suspension with a goal in the Copa del Rey on Wednesday as Barcelona survived a scare against Rayo Vallecano to reach the quarter-finals.
With Real Madrid and Atletico Madrid already out, another upset looked on the cards when Fran Garcia gave Rayo a surprise lead at Vallecas early in the second half.
But Messi tapped in Antoine Griezmann's pass to equalise before turning creator, sending Jordi Alba through, with Frenkie de Jong at the back post to seal a 2-1 victory.
Rayo sit fourth in Segunda, Spain's second tier, after being relegated from the top flight in 2019, with their fans and players at loggerheads with the club's president Raul Martin Presa amid the club's dramatic decline.
A victory over Barcelona, 30-time winners of the competition and now strong favourites to make it 31, would have delivered a brief boost to morale, even if this compelling cup tie never had the tension it deserved without the ground's usually raucous fans.
Still, Barcelona coach Ronald Koeman will be relieved to have made it to the quarter-finals and to see Messi on target again, the Argentinian taking his tally for the season to 15.
Messi had sat out the previous two games suspended after being sent off in the Spainsh Super Cup final defeat by Athletic Bilbao but looked refreshed and ultimately made the difference again.
There were less positive outings for Riqui Puig, Francisco Trincao and Junior Firpo, who all missed an opportunity to impress Koeman, who promptly whisked all three off after Rayo took the lead.
In the last eight, Barca join Sevilla, who had earlier made light work of struggling Valencia.
Valencia were beaten 3-0, their focus now on avoiding relegation from La Liga.
Real Betis, Villarreal and Levante also progressed on Tuesday.
Barca hit the woodwork twice in the first half. De Jong flicked a finish onto the crossbar and Puig struck the post after Trincao's shot spilled out.
Messi was collecting the ball from deep and driving through midfield but both he and the weaving Puig were often frustrated by a committed and aggressive Rayo defence.
Rayo rode their luck too, another effort grazing the crossbar early in the second half, this time from Messi, who opted to curl a free-kick towards the top corner from wide on the right.
But Rayo survived and when their first chance came, they took it. Breaking at speed, the ball was played wide to Alvaro Garcia, who stopped and then went again, leaving Clement Lenglet for dead.
His fired cross was fumbled by Neto, with Fran Garcia in the right place for a tap-in.
Koeman responded by throwing Jordi Alba, Pedri and Ousmane Dembele on for Puig, Firpo and Trincao.
Alba pulled back for Pedri and then De Jong threaded through Griezmann, who looked up and gave Messi an open goal at the back post.
The substitutes took Barca to a different gear and 10 minutes later, the comeback was complete as Messi clipped a spinning ball over the top for Alba to run onto and he slid a pass for De Jong to score his fourth goal in seven games.
Want stories like this in your inbox?
Sign up to exclusive daily email
More Stories from Football