Spain's ousted Prime Minister Mariano Rajoy leaves the chamber after a motion of no confidence vote at parliament in Madrid, Spain, June 1, 2018. Pierre-Philippe Marcou/Pool via REUTERS

MADRID (Reuters) - Spain’s former Prime Minister Mariano Rajoy on Tuesday announced he was resigning as leader of the conservative People’s Party (PP) after losing power in a no-confidence vote.

“It’s best for me, for the party, and it’s best for Spain,” Rajoy said to a standing ovation from party members.

The Socialists replaced the PP as the country’s leaders on Friday after parliament passed a no-confidence motion against Rajoy over a slew of corruption cases.

Rajoy had already been under fire for his handling of a secession crisis in Catalonia, with many voters turning away from his PP to the center-right Ciudadanos.

“He is doing the best thing for his party,” Teneo Intelligence analyst Antonio Barroso said. “It will open a renewal process inside the PP. It was the only party that had not renewed its leadership over the past years and it was dragging it down.”

Rajoy will still function as head of the party until a party congress agrees on his successor.

Twenty-nine people related to the PP, including a former treasurer and other senior members, were convicted in May of offences including falsifying accounts.

Rajoy became the first sitting prime minister in Spain to give evidence in a trial when he was called as a witness in the case last year, prompting calls for him to resign. He has denied any wrongdoing.

In his ruling, the judge said there was evidence the party ran a slush fund for many years and that the credibility of Rajoy’s testimony denying it “should be questioned”.