SAN JUAN, P.R. — After the revelation of homophobic, misogynistic and degrading text messages between Gov. Ricardo Rosselló of Puerto Rico and his aides and associates, protesters flooded the streets of San Juan, the capital, demanding his resignation.

The uprising, along with looming impeachment proceedings, swiftly derailed Mr. Rosselló’s administration. On Wednesday, the protesters gathered in the narrow streets leading to the governor’s mansion, La Fortaleza, in anticipation of his resignation. The announcement came in the final moments of the day, as people huddled over their phones for news: In a statement broadcast on Facebook and television, Mr. Rosselló said he would step down on Aug. 2.

The streets of Old San Juan burst into cheers. The celebrations lasted hours into the morning.