Piti scored the winner for Los Franjirojos with a goal in the 60th minute, firing home with his left footed shot into the lower left of the goal after intercepting a pass from Málaga's Eliseu.
Piti opened the scoring in the 11th before Martín Demichelis equalised with a header in the 49th minute.
Málaga are in third place with a record of five wins, two losses and three draws.
Rayo Vallecano now sit in ninth in the table with a record of four wins, five losses and one draw.
Piti ended the game with 14 completed passes and four total shots.
En route to the win, the Rayistas had the ball for 47.3% of the match.
The winners had 10 shots, including five on target.
Isco had two shots for Málaga, more than any of his team-mates.
The combination of Jesús Gámez to Joaquín was the most common during the match, as the two players connected 14 times.
Demichelis intercepted four passes.