Pedro Sanchez set to become Spain’s new prime minister after his socialist party secured enough votes to topple Rajoy.

Spain’s parliament ousted Prime Minister Mariano Rajoy on Friday in a no-confidence vote, paving the way for a takeover by opposition leader Pedro Sanchez.

This is the first time a head of government has been ousted since Spain transitioned to democracy in 1977.

Spanish Prime Minister Mariano Rajoy admitted defeat ahead of a no-confidence vote saying it had been “an honour” to serve the country.

Sanchez’s party filed the motion on May 25, a day after 29 people linked to Rajoy’s People Party (PP) were convicted of crimes, including embezzlement and money laundering, after a long-running corruption trial.

This situation could trigger a second political crisis in southern Europe, further unnerving financial markets already wrongfooted by delay in formation a government in Italy three months after a national election.

But how did this happen? Here is what we know:

Damaging court ruling

Fraud charges: Spain’s National Court delivered prison sentences to 29 business people and PP members on May 24, including some elected officials. They were charged with fraud, money laundering and tax evasion, putting Rajoy under the microscope

Rajoy survived a no-confidence vote in 2017.

His party’s first scandal, known as the Gurtel case, emerged in 2013 and led to the arrest of PP senator, and long standing treasurer, Luis Barcenas.

Barcenas testified that the PP kept a slush fund with donations from private businesses, and that some party officials received non-taxable bonuses in addition to their salaries.

Private messages: Spanish media has placed the scandal under serious scrutiny, giving coverage to the raid in PP’s national headquarters and the destruction of hard drives. It then released a series of private messages between Rajoy and Barcenas.

Last week’s court ruling looked at the kickbacks-for-contracts scheme in place between 1999 and 2005, when Rajoy was a party member.

The Popular Party was fined 245,000 euros ($286,000) for benefiting from “an authentic and efficient system of institutional corruption”.

Rajoy and other PP witnesses testified in court that the hidden accounts were unknown to them.

The motion and the parties