MADRID — With a pair of goals by defender Sergio Ramos, Real Madrid rebounded from two straight losses to beat Malaga 2-1 Saturday and guarantee first place at the halfway point of the Spanish league.

Ramos, coming off a difficult stretch in which he scored an own goal and was criticized for provoking opposing fans, scored twice in the first half to help Madrid snap a three-game winless streak and defend its league lead midway through the season.

"We had a great start to the season," Ramos said. "We have to stick together in the difficult moments, which for us is when we lose one match. Today's victory gives us a good boost and now we have to try to start another good run going forward."

The win gave Madrid 43 points, four more than Sevilla, which plays at last-placed Osasuna on Sunday. Third-placed Barcelona, now five points behind Madrid, plays at Eibar later Sunday.

Madrid will remain with a game in hand — at Valencia — after the weekend's matches.

"If we are in front at this point in La Liga, it means that we have been doing things correctly," Madrid forward Lucas Vazquez said. "Now it's important to keep working like this so we can keep winning matches and win the title in the end."

Madrid hasn't won the league since 2011-12.

Ramos put the hosts ahead at Santiago Bernabeu Stadium with a firm header off a corner taken by Toni Kroos in the 35th minute, and added to the lead just before halftime with a shot from close range after another set-piece cross by Kroos.

Ramos, who hadn't scored twice in a game since 2014, has reached six league goals this season for the first time in his career. Only Cristiano Ronaldo has more goals for Madrid this season, with 12.

"We all know what Sergio can do for us, especially in these set pieces," Madrid coach Zinedine Zidane said. "He has been great for us."

Ramos made headlines in the last couple of weeks after getting into a spat with fans of former club Sevilla, saying they disrespected him in a Copa del Rey match. In his next game against Sevilla, three days later in the league, the Madrid captain scored an own goal that allowed the hosts to come from behind and eventually win late to end Madrid's record run of 40 games unbeaten in all competitions.

Madrid's second loss in a row came on Wednesday at home against Celta Vigo in a first-leg match in the quarterfinals of the Copa del Rey, leaving Los Blancos under pressure.

"We needed this type of victory to gain confidence for the return match in the Copa," Vazquez said.

Malaga had a few chances early at Bernabeu, including a dangerous shot by Gonzalo Castro that struck the post when the game was scoreless. The visitors also threatened midway through the second half, when Juanpi scored Malaga's lone goal in the 63rd and Castro forced goalkeeper Keylor Navas to make a difficult save from close range only a minute later to avoid the equalizer.

"We are glad to leave with the three points despite the difficulties that we had," Zidane said.

Madrid left back Marcelo was substituted in the 25th because of an apparent muscle injury. Luka Modric also had to leave because of an apparent injury in the second half.

Ronaldo, playing in his 250th Spanish league game, was expected to undergo tests because of a foot injury that bothered him after the match.

___

VILLARREAL 0, VALENCIA 2

Valencia pulled off an emphatic 2-0 victory at sixth-placed Villarreal to win its second in a row after an eight-game winless streak in the league.

Carlos Soler and Santi Mina scored first-half goals for Valencia, which moved to 15th place and opened a seven-point gap to the relegation zone.

___

ESPANYOL 3, GRANADA 1

Espanyol ended its three-game winless streak with a comfortable home victory over struggling Granada and moved to 10th place.

Granada, winless in five matches, remained second-to-last but could drop bottom if last-placed Osasuna beats second-placed Sevilla at home on Sunday.

___

ALAVES 2, LEGANES 2

In a game between promoted clubs, defender Pablo Insua scored an 84th-minute equalizer for Leganes, which had its winless streak extended to six matches.

The result left the club only one spot away from the relegation zone.

Alaves, winless in three games, remained 12th.

___

Tales Azzoni on Twitter: http://twitter.com/tazzoni

___

This story has been corrected to show that Ramos now has six league goals this season instead of five.