Scandal-scarred Puerto Rico Gov. Ricardo Rosselló resigned as promised Friday afternoon and said he would swear in veteran politician Pedro Pierluisi as his replacement.

Thousands of Puerto Ricans cheered in front of the governor’s mansion when Rosselló’s resignation became official.

In an e-mailed announcement from his office, Rosselló said Pierluisi does not need confirmation from both houses of the US territory’s legislature because he was named secretary of state, the next in line to be governor, in a recess appointment this week.

The statement says Pierluisi will be sworn in to complete Rosselló’s term but did not say exactly when.

Puerto Rico’s House of Representatives had earlier voted to confirm Pierluisi as secretary of state. The House, which is controlled by Pierluisi’s New Progressive Party, voted 26-21 to confirm Rosselló’s handpicked nominee.

The House erupted into cheers when the deciding vote was cast.

But Pierluisi’s fate remains ­unclear.

While the secretary of state is next to line for the governor’s chair when the chief executive resigns, the issue of who is rightfully governor was almost certain to go to court.

Some politicians believe that because the legislature wasn’t in session when Pierluisi was appointed, he’s already secretary of state unless the legislature rejects him. Others argue that he still needs to be confirmed — some say just by the House of Representatives.

Still others say the Senate has to approve him, too.

If Pierluisi does not become governor, the position is taken by Justice Secretary Wanda Vázquez, who is not widely popular and already was the target of protests.

Rosselló promised to quit after weeks of protest over mismanagement and corruption in his administration and a series of leaked chats in which he and advisers denigrate a range of Puerto Ricans, including former New York City Council Speaker Melissa Mark-Viverito.

He is the first elected governor of Puerto Rico to resign.

Pierluisi vowed to serve the people. “My history of public service to our people should be sufficient proof of where my loyalties are and how I will work for our people,” said Pierluisi, who is both Puerto Rico’s nonvoting member of Congress and justice secretary.

With AP