The club from San Sebastian were two-up inside 14 minutes and extended their unbeaten league run to 13 games as they moved on to 54 points with seven games left to play.
Sociedad are eight points behind third-placed Atletico Madrid, who host Granada later on Sunday, but four ahead of Malaga and Valencia in fifth and sixth respectively.
Malaga grabbed a last-gasp winner to beat Osasuna 1-0 on Saturday, when Valencia were denied in equally-dramatic fashion by Espanyol in a 3-3 draw.
Striker Agirretxe netted twice from close range after low crosses from the left at a sun-drenched Vallecas stadium, and Rayo responded with a double tactical substitution of both their right-sided players in the 16th minute.
While it plugged the hole it failed to turn the game, and Rayo's push for a place in Europe next season faltered as they stayed ninth with 44 points.
- Sports & Recreation
- Atletico Madrid