Substitute Jonathan Viera converted a late penalty to see off Real Sociedad 1-0 and give Rayo Vallecano their first win in seven matches.
The Madrid side had been the better team in the opening 45 minutes, in which they hit the woodwork twice, but dropped their intensity in the second half, with Real Sociedad squandering a number of chances.
The visitors were made to pay for their wastefulness when Viera was fouled by Claudio Bravo in the 88th minute, and the 23-year-old made no mistake from the spot to double Rayo's points tally and take them off the bottom of the Primera Division table and up to 19th, with one point fewer than the Basques.
Both sides went into the game desperate for the three points, having not tasted victory since the first day of the season.
La Real were without the injured midfielder Xabi Prieto and centre-back Mikel Gonzalez, who was given permission to miss the game to attend the birth of his child. Jon Ansotegi came in for the defender, while David Zurutuza played in a more advanced role than he is used to, with the midfield pairing consisting of Markel Bergara and Gorka Elustondo.
Rayo coach Paco Jemez gave a full debut to Mexico international Nery Castillo, while Tottenham player Iago Falque made his comeback five weeks after getting injured five minutes into his Rayo debut against Levante.
The two teams have built reputations on their willingness to attack and this naturally made for an open game, with plenty of chances at either end.
Rayo goalkeeper Ruben Martinez dived to his right to keep out a powerful distance shot from Carlos Vela after 17 minutes, while at the other end Inigo Martinez produced a last-ditch tackle to prevent Castillo shooting on goal as he approached the six-yard box.
Adrian came inches away from scoring midway through the first half, turning Inigo Martinez in the area and lifting the ball over Bravo but onto the crossbar.
The hosts hit the woodwork again before the break, Lass picking out Joaquin Larrivey with a cross from the right hand side and the Argentinian heading the ball off the post from over 12 yards out.
Early in the second half, Ruben had to be quick off his line to scoop the ball from the feet of Imanol Agirretxe, who had turned his way past two Rayo defenders in the box and was shaping to shoot.
Before that the striker had missed the best chance of the game, side-footing wide just yards from the near post following a cut-back from Vela.
Substitute Haris Seferovic called Ruben into action again with 10 minutes remaining, running onto a ball from Griezmann and shooting straight at the Rayo goalkeeper.
The game appeared to have lost its earlier spark and looked to be heading for a stalemate, until Viera twisted his way into the box and was tripped by Bravo as he approached the byline.
Roberto Trashorras had missed the last penalty Rayo were awarded, and this time it was Viera who stepped up to take the spot-kick, sending the ball into the bottom corner to score.
Seferovic had one final attempt to equalise for La Real, trying his luck from outside the area, but Ruben gathered the shot comfortably.