Pedri celebrates Barça's first goal against Osasuna with Ousmane Dembélé.
CNN  — 

Gerard Piqué’s football career ended in ignominious fashion as he was red carded from the substitute’s bench, but Barcelona nevertheless secured an important 2-1 victory against Osasuna.

With Robert Lewandowski also red carded in the first half, Barça fought back from a goal down to move five points clear of rival Real Madrid at the top of La Liga.

Osasuna took an early lead in the sixth minute of Tuesday’s game when David García headed in from a corner.

Barcelona’s problems were then compounded as Lewandowski, the top scorer in La Liga this season, was given a second yellow card for a heavy challenge on García – just the second time in his career the striker has been sent off.

Tempers were running high as the players headed down the tunnel at halftime, so much so that Piqué was red carded for dissent without even coming on the pitch in the final game of his Barça career, which has seen him play more than 600 games over a 14-year period.

Lewandowski reacts after being given his marching orders against Osasuna.

READ: Qatar World Cup ‘is a mistake,’ says former FIFA President Sepp Blatter

A man down in the second half, the visiting side responded quickly through Pedri’s goal following Jordi Alba’s superb ball into the box.

The game looked set to end in a draw, but with five minutes remaining, Frenkie de Jong sent a superb long ball towards substitute Raphinha, who placed his dipping header over goalkeeper Aitor Fernández and into the Osasuna net.

“Our team’s shown the most maturity since I’ve been here,” Barça manager Xavi told reporters after the game. “We’ve had an hour with only 10 players, [Osasuna has] hardly created anything in that hour … Today is the victory of a family team and I’m very proud.”

Real Madrid has a chance to close the gap on the Blaugrana against Cádiz on Thursday, but the victory against Osasuna ensures Xavi’s side go into the seven-week club break for the World Cup at the top of La Liga.