MADRID (AP) — Real Madrid beat Barcelona for the second time in five days, a 2-1 win on Saturday which will do little to prevent its fierce rival from reclaiming the Spanish league title but should boost Jose Mourinho's team for its Champions League trip to Manchester United.

Sergio Ramos netted the winner in the 82nd minute when he rose up to head in Luka Modric's corner to give Madrid its first home league victory over Barcelona since 2008, in a game that grew testy toward the end and saw Barca goalkeeper Victor Valdes sent off for protesting.

Lionel Messi extended his Spanish league scoring record to 16 straight games when he equalized in the 18th minute to cancel out Karim Benzema's sixth-minute opener. That was Messi's 18th career goal in clasicos to tie Madrid great Alfredo Di Stefano's mark set in the 1950s and '60s, but Barcelona was otherwise a shadow of the thrilling team that until last season had dominated the rivalry in recent years.

"We deserved to win. The team has been strengthened by these clasico matches," Ramos said. "We are going to Manchester convinced (we will move on) but with respect for our opponent."

Madrid even managed without Cristiano Ronaldo for much of the match, as Mourinho rested the Portuguese winger until the final half hour with the game against United on Tuesday in mind.

Ronaldo scored twice on Tuesday in a 3-1 win over Barcelona at Camp Nou that put Madrid into the Copa del Rey final.

While Madrid remains 13 points behind Barcelona in the league, this result could allow second-place Atletico Madrid to cut the deficit to nine points on Sunday at Malaga.

Elsewhere, Jose Barkero leveled one minute from time to give Levante a 2-2 draw at Valencia in a city derby. Athletic Bilbao won 1-0 at Osasuna, and last-place Deportivo La Coruna drew 0-0 at home with Rayo Vallecano.

Barcelona has flopped in its last three games against major opponents after also losing 2-0 at AC Milan in the Champions League. It faces an uphill battle against the Italian side in the return leg on March 12.

"It's impossible to keep up the same level of play for 12 months," Gerard Pique said. "But it is true that we have played three or four bad games and that is serious because Barcelona always has to win. But this team will turn things around. I believe that because this is the best team I have ever played on. I'm surprised so many people have already jumped off the bandwagon."

Madrid, meanwhile, played with more confidence even with a number of backups in its starting lineup as it earned back-to-back wins over Barcelona for the first time since the 2007-08 season.

Midfielders Xabi Alonso and Mesut Oezil were also given a rest, along with forward Angel Di Maria. Madrid visits United on Tuesday with their last-16 tie poised at 1-1.

Barcelona assistant coach Jordi Roura, on the touchline for Tito Vilanova as he continues treatment for a throat tumor in New York, selected striker David Villa to accompany Messi and Thiago Alcantara to replace the injured Xavi Hernandez.

Even with several new faces, Madrid picked up where it left off at Camp Nou when a ball intercepted in midfield led to a swift goal in two passes, as Barcelona's defense conceded a goal for the 13th game in a row.

Ramos picked off Thiago's pass and fed Alvaro Morata on the left wing. The young forward sent a routine cross into the area to meet Benzema's run behind the distracted Javier Mascherano to volley home, leaving Messi shaking his head in disbelief at the ease his defense had allowed Madrid to go in front.

Messi, however, made sure Barcelona hit back when he beat Madrid's offside trap to reach Dani Alves' well-placed pass, cut back and fired under the backtracking Ramos with a sharp left-footed effort.

Messi reached the 50-goal mark for the third straight season with the goal, his league-leading 39th through 26 rounds.

Mourinho sent on Ronaldo in the 57th and he immediately earned a booking for fouling Gerard Pique. He hit the woodwork with a free kick.

Otherwise, the second half saw more physical play, petty fouls, and yellow cards than flowing play or clear scoring opportunities until the final minutes.

Ramos beat Pique to score the header that proved the difference. Pique, who gave away a penalty with a foul on Ronaldo on Tuesday at Camp Nou, completed his dismal week by giving away a corner kick and then letting Ramos outjump him to turn it into the net.

The game ended with the referee ignoring Ramos' trip of Adriano in the area that would have meant a stoppage-time penalty, leading to Victor Valdes being sent off for receiving two yellow cards for protesting vehemently.