Puerto Rico Governor Ricardo Rossello speaks during a Facebook live broadcast in the library of the governor's mansion, in San Juan, Puerto Rico January 24, 2018.

Puerto Rico Gov. Ricardo Rossello said late Wednesday that he will resign Aug. 2 after nearly two weeks of furious protests and political upheaval touched off by a leak of crude and insulting chat messages between him and his top advisors.

A crowd of demonstrators outside the governor's mansion in Old San Juan erupted into cheers and singing after his announcement on Facebook just before midnight

Addressing the protests, Rossello said, "The demands have been overwhelming and I've received them with highest degree of humility."

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 Rossello's resignation in Puerto Rico's biggest demonstrations since the protests that put an end to U.S. Navy training on the island of Vieques more than 15 years ago.

Rossello, a Democrat elected in 2016, is the first governor to resign in the modern history of Puerto Rico, a U.S. territory of more than 3 million American citizens.

Under Puerto Rico's constitution, the secretary of state would normally assume the governorship, but since Secretary of State Luis Rivera Marin became one of more than a dozen officials to resign in the uproar over the leak, leadership of the island would fall to Justice Secretary Wanda Vazquez. She would become Puerto Rico's second female governor.

In the 889 pages of conversation leaked on July 13, the chat participants mocked their constituents, including survivors of Maria, and made offensive remarks about women, with Rossello calling one a "whore."

The men also talked about politics and government contracts, and authorities this week issued search warrants for their cellphones in an investigation into whether they illegally divulged confidential government information. Lawmakers also began exploring the possibility of impeachment.

Over the weekend, Rossello posted a video on Facebook in which he announced he would not seek re-election in 2020 or continue as head of his pro-statehood political party, but his refusal to resign further angered Puerto Ricans and led to a colossal demonstration Monday on one of the capital's main highways.

Pressure on Rossello to step down included calls from Puerto Rico music stars Ricky Martin, Bad Bunny and Residente and a string of U.S. politicians, including members of Congress from both parties and several Democratic presidential candidates.

The upheaval comes as the island tries to restructure part of $70 billion in debt and cope with a 13-year recession that has led to an exodus of nearly half a million people to the U.S. mainland in the past decade. Many Puerto Ricans are resentful over the resulting pension cuts, school closings and other austerity measures.

The economic crisis is in part a result of previous administrations — including that of Rossello's father, Pedro — that overspent, overestimated revenue and borrowed millions as the island sank deeper into debt. In 2017, Puerto Rico filed for the equivalent of bankruptcy. Congress approved a financial package, and a federal board is overseeing the island's finances.

An MIT graduate with a doctorate in genetics, Rossello spent much of his time as governor fighting austerity measures and seeking federal funds after Maria devastated the island in September 2017, causing thousands of deaths and more than $100 billion in damage.

Nearly two years later, some 30,000 homes still have tarp roofs, power outages remain common, and Puerto Rico has received less than a third of the roughly $40 billion pledged by the U.S. government. Rossello complained earlier this year of unfair treatment and a hostile attitude from some U.S. officials.

The public's confidence has also been rocked by a recent string of corruption arrests involving such figures as the island's former education secretary and the one-time chief of health services.

This is a breaking news story. Please check back for updates.