Puerto Rico’s Governor Ricardo Rosselló has announced his resignation after days of mass street protests in the US territory.

Mr Rosselló, who had only on Sunday insisted he would stay on, said he would continue working until 2 August to allow an orderly transition.

He has been at the centre of a group text message scandal that has already led two top officials to resign.

The leaked messages revealed sexist, profane and homophobic comments.

The chat, which contained 880 pages of exchanges between the governor and 11 male allies, was leaked on 13 July and led to days of protests outside the governor’s mansion in San Juan.

Ricardo Rossello

What did Governor Rosselló say?

He recorded a video statement that was broadcast on Wednesday evening.

“I announce that I will be resigning from the governor’s post effective Friday, 2 August at 5pm,” Mr Rosselló said.

“I feel that to continue in this position would make it difficult for the success that I have achieved to endure,” he added.

Mr Rosselló’s announcement triggered celebrations on the streets of the capital San Juan.

On Monday, hundreds of thousands of people took to the streets, demanding Mr Rosselló’s immediate resignation.

The 40-year-old governor is leader of the New Progressive Party, a Puerto Rican political party which advocates US statehood.

Mr Rosselló will be replaced by the US Caribbean island territory’s Justice Secretary Wanda Vazquez.

On Sunday, in an attempt to appease protesters, he said he would not seek re-election next year.

“I hear you,” Mr Rosselló said in a Facebook video. “I have made mistakes and I have apologised. I know that apologising is not enough,” he added.

What are the secret messages?

Several of the texts mock victims of Hurricane Maria, which devastated the island in 2017 and may have led to more than 4,000 deaths.

In one instance, Mr Rosselló criticised the former speaker of the New York City Council, Melissa Mark-Viverito, saying people should “beat up that whore”.

When the island’s chief fiscal office wrote that he was “salivating to shoot” the mayor of San Juan, Mr Rosselló replied: “You’d be doing me a grand favour.”

What has been the reaction to the scandal?

Local newspaper El Nuevo Día called on the governor to resign in its Monday editorial.

“Puerto Rico has spoken up, not only as a strong, broad and united voice, but as the right voice,” the editorial said. “With a gesture of nobility and humility, Governor, it is time to listen to the people. You have to resign.”

San Juan Mayor Carmen Yulin Cruz said in a Twitter message on Monday: “They can’t deny it: The power is in the street.”

Singer Ricky Martin, who was targeted in the secret messages, was among those calling for the governor to resign, as well as Hamilton creator Lin-Manuel Miranda and reggaeton star Bad Bunny.

“They mocked our dead, they mocked women, they mocked the LGBT community, they made fun of people with physical and mental disabilities, they made fun of obesity. It’s enough. This cannot be,” Martin said in a video on Twitter.

The island’s political crisis also made headlines throughout mainland US. Many echoed the New York Times editorial board, which wrote that the “callousness and partisan self-dealing” exposed by the messages serve as exorbitant strain for the long-suffering island, effectively “rubbing salt into a long-festering wound”.

“The Puerto Rican people have no use for petty political feuding,” the New York Times wrote. “Their territory is struggling under the weight of government corruption, incompetence and indifference. Having been failed by their leaders at every level, they are out of patience. They deserve better.”

US President Donald Trump has also called on the governor to resign.