A crowd of thousands outside the governor's mansion in Old San Juan erupted in cheers and song over his announcement on Facebook, made just before midnight on Wednesday.
"Despite expecting to serve 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," a shaken-looking Rosselló said in an address in which he listed his accomplishments before making clear he will step down Aug. 2.
The 40-year-old Democrat and son of a governor, Rosselló became the first governor to resign in the modern history of Puerto Rico, a U.S. territory of more than 3 million American citizens. He is more than halfway through his four-year term.
He said Justice Secretary Wanda Vázquez will take over, becoming Puerto Rico's second female governor.
"It's historic, but we have to be cautious. What will happen beyond this? There are concerns, but there is also hope," designer Jalil Serrano said. Gesturing to the young crowd outside the mansion, he said, "This belongs to them."
Daniel López, a businessman also in the protest, wiped tears from his eyes as people leaped into the air, beat drums, waved flags, hugged and cried, "We did it!"
"This is for the future of my family," López said. "It's big, what's happened."
Rosselló's announcement - made amid threats of impeachment from lawmakers - came after a bizarre standoff unfolded in Old San Juan. The governor pledged to deliver a message to the people of Puerto Rico, but hour after hour passed in unexplained silence while thousands of protesters chanted demands for his resignation. An announcement was first expected at 5 p.m., then finally came less than a half-hour before midnight.
Puerto Rico Rep. Gabriel Rodríguez, a member of Rosselló's pro-statehood party, said legislators had agreed to set aside the impeachment process and give the governor until 5 p.m. to announce that he was going to resign.
At one point, dozens of officers in full riot gear marched out of the governor's mansion toward protesters.
"We want peace, and they want war!" the crowd yelled.
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.
PREVIOUS COVERAGE: Puerto Ricans gather for largest protest yet to oust Gov. Ricardo Rossello
In reaction, tens of thousands took to the streets to demand Rosselló'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.
The chat participants discussed the awarding of government contracts in ways that some observers called potentially illegal. They also insulted women and mocked constituents, including victims of Hurricane Maria. Rosselló called a female politician a "whore," referred to another as a "daughter of a bitch," and made fun of an obese man with whom he posed in a photo.
Earlier this week, a judge issued search warrants for the cellphones of government officials involved in the chat. One of the search warrants said officials in the conversation may have illegally divulged confidential government information.
More than a dozen government officials have resigned since the chat was leaked earlier this month, including Rosselló confidant and chief of staff Ricardo Llerandi, former Secretary of State Luis Rivera Marín and former chief financial officer Christian Sobrino, who also held five other positions.
Under Puerto Rico's constitution, the secretary of state would normally assume the governorship, but since that post is vacant, Vazquez is in line to succeed Rosselló.
Over the weekend, Rosselló posted a video on Facebook in which he announced he would not seek re-election in 2020 or continue as head of his 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.
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 Rosselló'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, Rosselló 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. Rosselló 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.