(CNN) -- Atletico Madrid moved back ahead of city rivals Real Madrid in La Liga on Sunday with a 4-2 away win at Rayo Vallecano.
An entertaining match got off to a lively start as David Villa opened the scoring for the visitors in the eighth minute.
The former Barcelona forward scored from close range after receiving a pass from strike partner Diego Costa.
The lead looked as though it would be short-lived when Rayo were awarded a penalty four minutes later following Javier Manquillo's foul on Alberto Bueno inside the box.
But Jonathan Viera failed to convert the spot kick -- his shot saved by Atletico keeper Thibaut Courtois.
The home side were punished for their profligacy when Arda Tudan doubled the lead in the 30th minute.
Viera made amends for his penalty miss with a goal five minutes before the break, but Tudan's second strike in the 44th minute restored Atletico's two-goal cushion.
Costa, who has been linked with English Premier League side Chelsea during the January transfer window, weighed in with a fourth 15 minutes before the end, before Argentine striker Joaquin Larrivey headed home a consolation goal moments later.
Diego Simeone's side will be happy to get back to winning ways after successive home draws. Three points gives them 54 in total from 21 matches, one point more than Carlo Ancelotti's men, who assumed top spot for 24 hours after beating Granada 2-0 at the Bernabeu on Saturday.
Turbulent week for Barca ends with a win
Barcelona's players were looking forward to getting back on the pitch after a turbulent week off it for the club's bosses.
Sandro Rosell dramatically quit as Barcelona president on Thursday after a Spanish judge decided to investigate the $78m deal that brought superstar Neymar from Brazilian club Santos to the Catalan giants last June.
Rosell, who denies any wrongdoing, spent three-and-a-half years in charge and has been replaced by vice-president Josep Maria Bartomeu.
Speaking on Saturday, head coach Gerardo Martino said: "It's not the kind of situation we would want to be in. The players are sad but they know the best way forward is to do things well in footballing terms.
"The dressing room seems in good shape to me. They are enjoying life at Barca and they need to win like every year and respect the club's playing style in winning trophies."
That aim is still very much on track after dispatching Malaga 3-0.
Gerard Piqué's right-footed shot in the 40th minute gave Barca a vital lead at the break which they quickly consolidated.
Pedro made it 2-0 nine minutes into the second half with Alexis Sanchez adding a third on the hour mark.
The win puts the reigning champions back on top, level on points with Atletico but with a superior goal difference.
In La Liga's two remaining fixtures on Sunday, Athletic Bilbao thrashed Osasuna 5-1 to consolidate fourth place while Almeria rise to 15th after a 1-0 win against Getafe.