MADRID (AP)With an improbable win, Barcelona made sure it will go into the World Cup break at the top of the Spanish league standings.

Robert Lewandowski was shown his first red card in nearly a decade and Gerard Pique was sent off from the bench in his last career match, but Raphinha scored late as Barcelona rallied to defeat Osasuna 2-1 and secure the Spanish league lead ahead of the World Cup stoppage.

Lewandowski’s second career red card came in the first half of Tuesday’s victory, which left the Catalan club five points ahead of Real Madrid. Madrid, which has a game in hand, endured its first league loss of the season, 3-2 at Rayo Vallecano on Monday. The defending champions will host relegation-threatened Cadiz on Thursday.

Pique was sent off for complaining to the referee following the halftime whistle. The veteran Spain defender had made Xavi Hernandez’s squad even though he bid farewell at the Camp Nou at the weekend after announcing his retirement from soccer.

Lewandowski, who hadn’t been sent off since 2013 while still playing for Borussia Dortmund, was shown his second yellow card in the 31st minute after going hard into the body of Osasuna defender David Garcia away from the ball.

Garcia had opened the scoring for the hosts with a header in the sixth minute. Pedri Gonzalez equalized in the 48th with a strike from inside the area after the Osasuna defense failed to fully clear a cross by Jordi Alba, and substitute Raphinha netted the winner in the 85th with a header after a long cross by Frenkie de Jong. The Brazilian forward had entered the game seven minutes earlier.

”It was a difficult match and it got even harder after Robert was sent off,” Pedri said. ”We knew we would have an opportunity, and got the goal when we had the chance.”

Barcelona seemed beaten but Raphinha scored after breaking free from the defenders to get to De Jong’s long ball, with his header from the edge of the area going over the goalkeeper and into the net.

Osasuna was trying to earn its third straight win, and fourth in its last five matches, with its only setback in that stint a draw at Girona. A victory would have left the Pamplona team in third place in the standings. Instead it dropped to sixth.

”It’s a shame, we are upset,” Garcia said. ”We didn’t play well in the second half and paid a high price for it. We should have gone for the second goal to try to close out the match.”

Barcelona has won five games in a row in the league since losing the ”clasico” at Madrid last month, but in the meantime it was eliminated in the group stage of Champions League for the second season in a row.

FAN VIOLENCE

A group of radical Barcelona fans attacked Osasuna supporters at a bar before the match in Pamplona.

The Barcelona fans reportedly used knives and sticks in the attack, leaving a few Osasuna supporters with minor injuries.

There were no reports of arrests.

Both clubs condemned the incident.

ATHLETIC RISES

Athletic Bilbao defeated Valladolid 3-0 at home to move to third place with its second win in three matches.

Gorka Guruzeta scored a goal in each half and Dani Vivian added the third near the end of the match at San Mames Stadium.

Valladolid stayed in 10th place.

WINLESS ELCHE

Elche’s struggles as the only team without a league win continued with a 2-1 home loss to Girona.

The hosts went ahead with a goal by Pol Lirola in the 16th, but Girona rallied with an equalizer by Ivan Martin in the 39th and a winner by Taty Castellanos in the 66th.

It was the second consecutive win for Girona, which sits in 13th place.

Last-place Elche has 10 losses — including in its last three matches — and four draws. It is seven points behind second-to-last-place Cadiz, which has a game in hand.

AP World Cup coverage: https://apnews.com/hub/world-cup and https://twitter.com/AP-Sports

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