SAN JUAN, Puerto Rico (AP) — Puerto Rico's House of Representatives voted Friday to confirm Pedro Pierluisi as secretary of state, removing an important obstacle to the veteran politician becoming governor with an hour to go before Ricardo Rosselló was expected to step down.

The House voted 26-21, with one abstention, to confirm Rosselló's nominee and potential successor. The legislature, which is controlled by Pierluisi's New Progressive Party, erupted into cheers when the deciding vote was cast.

But Pierluisi's fate remains unclear. The secretary of state is next to line for the governor's chair when the chief executive resigns. However, the issue of who is rightfully governor is almost certain to go to court.

Rosselló was due to step down at 5 p.m., a resignation he promised in response to weeks of popular protest over mismanagement, and a series of leaked chats in which he and advisers denigrated a range of Puerto Ricans.

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

The down-to-the-wire maneuvering risked political chaos and a constitutional crisis and sowed bitterness and pessimism among Puerto Ricans about the fate of their island, which has been battered by years of bankruptcy and Hurricane Maria in 2017, one of the worst natural disasters in U.S. history.

Only days ago, there was jubilation over the success of the popular movement to force Rosselló out of office over mismanagement and a series of leaked chats in which he and advisers denigrated a wide range of Puerto Ricans.

"People are disgusted with the government in general, not just Ricardo Rosselló, everyone," said Janeline Avila, 24, who recently received her degree in biotechnology.

Some believe that because the legislature was not in session when Pierluisi was appointed, he's already secretary of state unless the legislature rejects him.

Others argued that he still needed to be confirmed by the House or both the House and Senate.

One amendment states that everyone in line to become governor has to be confirmed by both House and Senate, except for the secretary of state.

Constitutional law professor Carlos Ramos and other legal experts questioned the legal validity of that amendment and believed Pierluisi must be confirmed by the House and Senate because the amendment contradicts the intent of the constitution and its statement of motives.

Lawmakers and Pierluisi himself expressed concern that the continuing political uncertainty would damage Puerto Rico's efforts to get federal funds to recover from the hurricane and confront the economic crisis.

Several legislators have accused Pierluisi of a conflict of interest because he worked for a law firm that represents a federal control board overseeing the island's finances, a body that has repeatedly clashed with local officials over demands for austerity measures.

Pierluisi, whose brother-in-law is the board's chairman, tried to dispel those concerns in his opening remarks.

"Who better than me to advocate for our people before the board? Who better than me to facilitate the process that will force the board to leave? That is what we all want," he said.

The board was created by Congress to oversee the restructuring of more than $70 billion in public debt after Puerto Rico declared a form of bankruptcy.

Pierluisi told lawmakers he is against several austerity measures demanded by the board, including laying off public employees and eliminating a Christmas bonus.

He said he supports public-private partnerships and the privatization of the island's public power company.

"The people want a change, and I don't blame them," he said.

A key obstacle for Pierluisi has been Senate President Thomas Rivera Schatz, who has said he would not vote for Rosselló's nominee and wants to run for governor himself next year. Several legislators have said they prefer Rivera Schatz over Pierluisi, but the Senate leader is a powerful figure deeply associated with Puerto Rico's political and business elite, and his elevation to the governorship could re-ignite popular outrage.

Rivera Schatz has scheduled a Senate hearing on Pierluisi for Monday.

Pierluisi was Puerto Rico's non-voting representative in Congress from 2009 to 2017 and then ran against Rosselló in the 2016 primaries and lost. He also served as justice secretary under Rosselló's father, Pedro Rosselló, when he was governor.

The political infighting and paralysis followed a wave of street protests against Rosselló, who joins more than a dozen government officials who have resigned in the wake of an obscenity-laced chat in which they made fun of women, gay people and hurricane victims.

Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.