Robert Lewandowski pulled a goal back late on, but it proved too little, too late for Barca, who tasted defeat in the league for just the third time this season.
Rayo climbed to ninth with the three points, while Barca remain 11 points clear of Real Madrid at the top of the table with just seven games to be played.
1. Below-par Barça ruffled by Rayo again
Barcelona coach Xavi Hernandez warned his players how tough Wednesday's trip to Vallecas would be. They lost there 1-0 last season, a result which cost Ronald Koeman his job, and have struggled home and away against Rayo since they returned to LaLiga in 2021.
Rayo have now picked up 10 points from 12 against Barca over the last two seasons. Robert Lewandowski's late goal was the first time Barca have scored against them in four meetings, too.
It's not just the results, either. Rayo have been worthy winners. Andoni Iraola's side were better than Barca from the off. They were more intense and better with the ball. Marc-Andre ter Stegen had already saved from Sergio Camello when Alvaro opened the scoring in the 19th minute with a smart finish.
Stole Dimitrievski denied Lewandowski at the other end and the Polish striker then had a goal ruled out for a marginal offside, but Barca forays forward were otherwise rare. Fran Garcia, on loan from Real Madrid, deservedly added the second as Rayo became just the second team to score twice against Barca in LaLiga this season.
2. Defeat won't dent LaLiga title hopes
Lewandowski pulled a goal back in the 83rd with an excellent finish to take his tally in the league to 18 for the season. It did not spark a late comeback, though, as Xavi's side missed the chance to capitalise on Madrid's 4-2 loss to Girona on Tuesday.
Defeat should not dent Barca's charge towards a first LaLiga title since 2019. They remain 11 points clear at the top and, with just seven games to go, it is hard to see them surrendering their lead from here, even if they continue to play like this.
However, how they get over the line may influence the narrative around their success. Did they win the title or did Madrid lose it? Just how far have they come under Xavi? How many changes are needed to the squad to be able to compete in Europe again?
3. Another big win for Iraola and Rayo
The second half of the season has been strange for Rayo. After an excellent start to the campaign had them competing for the European places, a run of just one win in 10 games has left them in no man's land in the standings.
However, when the big teams come to Vallecas, they come alive. They got the better of Barca at home last season and beat Madrid 3-2 earlier in the current campaign. The wins are nearly always accompanied by exciting, front-foot football.
Iraola's work at Rayo, taking them back into the top flight and overperforming once there, has naturally seen him lined with other jobs. He has already turned down the chance to move to the Premier League, but more offers will continue to arrive on the back of performances like this.
Best and worst performers
BEST: Isi Palazon, Rayo Vallecano.
Ran the game in the first half. The only way Barca could stop him was by fouling him.
BEST: Fran Garcia, DF, Rayo Vallecano.
The left-back is on loan from Real Madrid, who will be seriously considering giving him a chance at the Santiago Bernabeu next season.
BEST: Alvaro Garcia, DF, Rayo Vallecano.
Took his goal well but was most notable for his pressing, winning the ball back five times as the home side hounded Barca in possession.
WORST: Marcos Alonso, DF, Barcelona.
The makeshift centre-back had a torrid night in Vallecas and was taken off early in the second half.
WORST: Gavi, MF, Barcelona.
Brushed off the ball easily in the first half and booked for repeated fouls on Isi.
Highlights and notable moments
Rayo pounced on Barcelona early thanks to Alvaro Garcia's early goal and kept the visitors at arm's length for the rest of the night.
RAYO TAKE THE LEAD OVER BARCELONA 👀 pic.twitter.com/rrsvExP2zk— ESPN FC (@ESPNFC) April 26, 2023
After the match: What the managers, players said
Barcelona coach Xavi Hernandez, on the loss: "We didn't play well, we were never comfortable in the game. The chances we did have, we did not take and then the second goal really penalised us. We tried until the end, but Rayo are worthy winners. They press really well and we were never comfortable. The result really annoys us but it's another game week down."
Xavi, on the title race: "The message is simple: there is still a long way to go. Nothing is done yet. LaLiga is not won, I have said it many teams. It will take a lot to win it. Every game away from home is a battle. Madrid are losing games, Atletico are having to scrap to win, we have lost... but we are annoyed because this was a really good opportunity to extend the gap."
Rayo coach Andoni Iraola, on the win: "You have to do a lot of things and have that element of fortune to beat Barca. We made the game uncomfortable for them. We were dangerous in transition. Both goals come from winning the ball back and then attacking quickly. Now we can say that we will be here (in LaLiga) again next season with 43 points."
Key stats (provided by ESPN Stats & Information)
- Barcelona: greater than 99% chance of winning LaLiga this season, according to FiveThirtyEight's Soccer Power Index (leads Real Madrid by 9 points with 7 games remaining).
- Rayo Vallecano: defeated Barcelona and Real Madrid at home in same LaLiga season for 2nd time in club history and 1st since its first LaLiga season in 1977-78.
- Rayo Vallecano: joins Real Madrid as only clubs to score multiple goals in a LaLiga game against Barcelona this season.