Puerto Rico’s Supreme Court ruled on Wednesday that the swearing-in of Pedro Pierluisi as governor was unconstitutional, paving the way for Justice Secretary Wanda Vázquez to take over the post.

Pierluisi took the oath of office last Friday when embattled Gov. Ricardo Rosselló resigned after it was revealed he shared derogatory text messages with his advisers.

“The governor’s oath of office was unconstitutional,” the court said. “Therefore, Hon. Pedro R. Pierluisi Urrutia can’t continue his work as Governor after this Opinion and Sentence becomes effective.”

The decision, which cannot be appealed, took effect at 5 p.m.

The unanimous ruling cleared the way for Justice Secretary Vázquez to become the island’s next governor.

Vázquez took the oath of office in the early evening at the Supreme Court before leaving without making any public comment.

Although she said last month that she had “no interest” in the position, she changed course after the ruling and said she would accept it because “Puerto Rico needs assurance and stability.”

“Our actions are aimed will be aimed toward that end and it will always come first,” Vázquez, who has been criticized for not prosecuting corruption in her and Rosselló’s political party, said in a statement.

Pierluisi was appointed secretary of state by Rosselló – making him next in the line of succession – but only the House approved the nomination.

The Senate then challenged Pierluisi’s legitimacy.

“It’s unconstitutional to allow a Secretary of State to become Governor without having been confirmed by both legislative chambers,” the court said in a press release.

Rosselló was forced from office after weeks of massive protests, stemming from the messages that insulted women, belittled homosexuals and mocked victims of Hurricane Maria.

With Post wires