Puerto Rico’s governor Ricardo Rossello has resigned after two weeks of furious protests following the publication of a stream of offensive private chat messages between him and his advisers.

Mr Rossello had insulted women and mocked constituents, including victims of Hurricane Maria. He had called a female politician a “whore”, referred to another as a “daughter of a b****”, and made fun of an obese man with whom he posed in a photo. He had joked about the murder of the mayor of Puerto Rican capital San Juan and had also made homophobic remarks about others.

Hundreds of thousands protested in the streets and demanded his resignation.

On Wednesday evening a crowd of thousands outside the governor’s mansion in Old San Juan erupted into cheers and singing after Mr Rossello posted a video announcement on Facebook just before midnight.

“My only priority has been the transformation of our island and the well-being of our people,” a shaken-looking Mr Rossello said in an address that listed his accomplishments before making clear he was resigning.

Bringing aid to Puerto Rico Show all 20 1 /20 Bringing aid to Puerto Rico Bringing aid to Puerto Rico Crew chief Kenney shelters under the blade of an HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit preparing to take off during recovery efforts following Hurricane Maria, in Isla Grande, Puerto Rico, October 6, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico An HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit takes off behind Crew Chief Alexander Blake and his fellow soldiers during recovery efforts following Hurricane Maria, in Morovis, October 5, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Crew member Bynum stands in tropical rain as a HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit prepares to take off during recovery efforts following Hurricane Maria, in Isla Grande, October 6, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico UH-60 Blackhawk helicopter pilot Chris Greenway receives a hug from a woman thanking him for water as he works with the First Armored Division's Combat Aviation Brigade during recovery efforts following Hurricane Maria, in Verde de Comerio, October 7, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico A man carries a case of water away from an HH-60 Blackhawk helicopter after soldiers working with 101st Airborne Division's "Dustoff" unit dropped off relief supplies during recovery efforts following Hurricane Maria, in Jayuya, October 5, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Crew chief Alexander Blake from 101st Airborne Division's "Dustoff" unit loads water into a helicopter during recovery efforts following Hurricane Maria, in Isla Grande, October 5, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Residents wait for soldiers in UH-60 Blackhawk helicopters from the First Armored Division's Combat Aviation Brigade to deliver food and water during recovery efforts following Hurricane Maria, in San Lorenzo Reuters Bringing aid to Puerto Rico An HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit lands in a field to avoid lightning during recovery efforts following Hurricane Maria, in Manati, October 5, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Residents hold their hands aloft to signal that they need water as UH-60 Blackhawk helicopters from the First Armored Division's Combat Aviation Brigade fly past during recovery efforts following Hurricane Maria, near Ciales, October 7, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Tropical rain splashes on a runway as HH-60 Blackhawk helicopters from 101st Airborne Division's "Dustoff" unit wait for weather to clear during recovery efforts following Hurricane Maria, in Isla Grande, October 6, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Pilot Eldwin Bocanegra Torres speaks with residents isolated by landslides in the mountains after unloading water and food from a helicopter during recovery efforts following Hurricane Maria, near Utuado, October 10, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Residents stand in front of wind-damaged trees as they wait for soldiers in UH-60 Blackhawk helicopters from the First Armored Division's Combat Aviation Brigade to deliver food and water during recovery efforts following Hurricane Maria, in San Lorenzo, October 7, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico The contents of a home are seen from the air during recovery efforts following Hurricane Maria near Utuado, October 10, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Thomas looks out of the window of an HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit, loaded with relief supplies, during recovery efforts following Hurricane Maria in Isla Grande, October 6, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico A message written on the rooftop is seen from the air during recovery efforts following Hurricane Maria near Humacao, October 10, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico A HH-60 Blackhawk helicopter from 101st Airborne Division's "Dustoff" unit lands in a field during recovery efforts following Hurricane Maria in San Sebastian, October 6, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Sergeant First Class Eladio Tirado, who is from Puerto Rico, looks for a landing spot for a UH-60 Blackhawk helicopter from the First Armored Division's Combat Aviation Brigade, during recovery efforts following Hurricane Maria near Ciales, October 7, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Boys carry water away from an HH-60 Blackhawk helicopter after soldiers working with the U.S. Army's 101st Airborne Division's "Dustoff" unit dropped off relief supplies during recovery efforts following Hurricane Maria, in Jayuya, October 5, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Sergeant First Class Eladio Tirado from the First Armored Division's Combat Aviation Brigade, who is from Puerto Rico, speaks with residents as he helps during recovery efforts following Hurricane Maria, in San Lorenzo, October 7, 2017 Reuters/Lucas Jackson Bringing aid to Puerto Rico Residents peek through a fence at helicopters from 101st Airborne Division's "Dustoff" unit that had parked in a locked field during recovery efforts following Hurricane Maria, in Lares, October 6, 2017 Reuters/Lucas Jackson

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

Addressing the protests, he said: “The demands have been overwhelming and I’ve received them with the highest degree of humility.

“Despite expecting to service the term that the people democratically elected me to, today I feel that continuing in this position represents a threat to the success we have achieved.”

His eventual announcement came after a bizarre, hours-long standoff had unfolded in colonial Old San Juan.

The governor had earlier in the day pledged to deliver a message to the people of Puerto Rico, but then hour after hour passed in unexplained silence while thousands of protesters chanted demands for his resignation.

A statement was first expected at 5pm, but finally came in the form of a video address less than a half-hour before midnight.

The 40-year-old son of a former governor, Mr Rossello has become the first chief executive to resign in the modern history of Puerto Rico, a US territory of more than three million American citizens without full representation in Congress or the right to vote for president.

On Tuesday, it was announced a Puerto Rico judge had issued search warrants for the mobile phones of government officials involved in the chat as part of an investigation.

Demonstrators celebrate in San Juan after the resignation of Puerto Rico governor Ricardo Rossello (Reuters)

One of the search warrants said officials had used the chat to transmit official and confidential information to private citizens in potential violation of ethics laws.

More than a dozen government officials have resigned since the chat was leaked earlier this month, including Mr Rossello’s confidant and chief of staff Ricardo Llerandi, former secretary of state Luis Rivera Marin and former chief financial officer Christian Sobrino, who also held five other positions.

The obscenity-laced online messages involving the governor and 11 other men infuriated Puerto Ricans already frustrated with corruption, mismanagement, economic crisis and the sluggish recovery from Hurricane Maria nearly two years ago.

In reaction, tens of thousands took to the streets to demand Mr Rossello’s resignation in Puerto Rico’s biggest demonstrations since the protests that put an end to US Navy training on the island of Vieques more than 15 years ago.

Celebrations continued long into the night after Mr Rossello’s resignation (AP)

Over the weekend, Mr Rossello posted a Facebook video in which he offered to resign as leader of his pro-statehood political party and not to seek re-election in 2020, but he did not offer to resign.

His refusal to stand down despite the publication of the chat messages added fuel to the frustration of angry Puerto Ricans, and led to a colossal demonstration on Monday on one of San Juan’s biggest roads.

Puerto Rico’s justice secretary, Wanda Vazquez Garced, will assume the post less than halfway through Mr Rossello’s four-year term, becoming Puerto Rico’s second female governor.