Real could have leapfrogged fifth-placed Villarreal and moved to within five points of Athletic Bilbao in the final Champions League spot with victory at Anoeta.
Instead, Jagoba Arrasate's team stay in sixth place, on 43 points.
In a frantic opening to the game, Inigo Martinez headed the hosts into an early lead after two minutes, only for Rayo to win a penalty when Jose Angel caught Joaquin Larrivey just two minutes later. Larrivey dusted himself to take the spot kick and level things up.
Sociedad took the lead for a second time just before the break when Pardo Gutierrez fired past keeper Ruben but two minutes after the restart, Rayo hit back swiftly once again.
This time it was Alberto Bueno who equalised, stabbing home after a goalmouth scramble, and the visitors went on to grab what proved to be the winner when Ruben Rochina finished off a neat passing move on 67 minutes.
Victory for Rayo - just their eighth of the campaign - was enough for the relegation-threatened side to move level on 26 points with fellow strugglers Real Valladolid and Almeria. The Madrid-based club do, however, remain in 19th place.
In the night's other game, Malaga moved above Osasuna in the table with 2-0 away from home.
- Sports & Recreation
- Inigo Martinez
- Athletic Bilbao