Oier Sanjurjo had them ahead with an early goal and it was not long before Oriol Riera had doubled the lead.
A goal from Roberto Torres looked to have sealed the win but Miguel de las Cuevas was sent off and Alejandro Galvez reduced the arrears to produce a tense last 20 minutes.
Osasuna opened the scoring in the very first minute as the home side won an early corner and Torres' set-piece was met by Oier who headed home from six yards.
Yago Falque dragged a shot wide as he tried to get Rayo back into it in the ninth minute but just three minutes later they fell further behind.
De las Cuevas provided the pass from the left and Riera was on hand to fire home right-footed and double the lead.
Jonathan Viera was the next to try his luck for the visitors but Osasuna were having the best of it and first Riera and then Alejandro Arribas both went close with headers.
Rayo began to grow into the game, though, and Alberto Bueno saw his shot blocked away before Viera brought an impressive save from Andres Fernandez from distance.
The visitors began the second half in lively fashion and Falque saw both a shot and a header from the resulting corner saved before Osasuna scored against the run of play.
Raoul Loe provided the pass and Torres slotted home from the edge of the penalty area.
Roberto Trashorras was thwarted by Fernandez as Rayo continued to press and they were handed a lifeline in the 66th minute when De la Cuevas was sent off.
Galvez grabbed a goal back from close range just four minutes later but that was to complete the scoring as Osasuna closed out the win.