The new governor of Puerto Rico has been ousted after the territory's Supreme Court found his appointment to be unconstitutional.

Pedro Pierluisi was appointed last Friday after former Gov. Ricardo Rosselló resigned in the wake of a scandal involving 900 pages of chats. Pierluisi had been appointed as secretary of state, the position second in line, though he had not yet been confirmed by the Puerto Rico House or Senate.

A constitutional amendment in 2005 stated that the secretary of state could assume the office of governor even without being confirmed by the House and Senate, but the Supreme Court found that amendment to be unconstitutional in a Wednesday decision.

The findings concluded that Pierluisi "cannot continue in the position of governor," a decision that would become effective at 5 p.m. on Wednesday.

Rosselló's resignation last Friday came after weeks of protests by citizens of Puerto Rico demanding that he step down. The leaked chats revealed pages of incendiary conversations between Rosselló and other government figures that included homophobic and misogynistic comments, as well as jokes about victims of Hurricane Maria in 2017.

The next in line for the governorship of Puerto Rico is Secretary of Justice Wanda Vázquez, who has previously asserted that she did not want the job, but that she would take it if necessary. Pierluisi also stated that he would graciously move aside if that is what was required.

Pierluisi is an ally of Rosselló and fellow member of the New Progressive Party, as is Wanda Vázquez, who is expected to be sworn in later on Wednesday.

The president of the Puerto Rico Senate praised the decision of the Supreme Court on Wednesday after suing for Pierluisi's removal for illegitimacy. "With absolute legitimacy, we will seek true peace and stability," said Senate President Rivera Schatz.