Puerto Rico's Gov. Ricardo Rossello says he'll resign effective Aug. 2 in the face of public furor over an obscenity-laced online chat that showed the governor and close advisers insulting women and mocking constituents, including the victims of Hurricane Maria.

Rossello, 40, is the first governor to resign in the modern history of Puerto Rico, a territory of 3.2 million U.S. citizens that is mired in a 13-year recession and is still recovering from the Category 4 hurricane two years ago.

Public outrage over the leaked chats and federal corruption charges against former government officials sparked massive demonstrations across San Juan in the largest protest movement on the island since Puerto Ricans successfully marched to demand an end to U.S. Navy military training on the island of Vieques more than 15 years ago.

Justice Secretary Wanda Vazquez will become the new governor.

Rossello, a first-term governor for the U.S. territory, had previously resisted calls to step down over a scandal local media have dubbed "Rickyleaks."

Thousands erupted into cheers and singing after Rossello's announcement. (Marco Bello/Reuters)

Puerto Rico has been rocked by protests for nearly two weeks after offensive chat messages from July 13 between Rossello and his aides, several of whom have already quit, were made public. The messages contained profane language used to describe female politicians and gay Puerto Rican celebrities, including singer Ricky Martin.

An independent panel of lawyers commissioned by the Speaker of Puerto Rico's House of Representatives to investigate the offensive messages found four felonies and one misdemeanor may have been committed during the Telegram message group chats, one of the lawyers, Luis Rodriguez-Rivera, said in an email.

Thousands of protesters outside the powder-blue-and-white governor's mansion grew ever more impatient for news from Rossello earlier on Wednesday. Rows of riot police marched past the residence, dubbed "the Fortress," in preparation for what some thought could become a night of confrontation if Rossello did not step down.

Rapper Residente, centre, celebrates with other protesters in Old San Juan, Puerto Rico, following Rossello's announcement. (Joe Raedle/Getty Images)

Puerto Rico's constitution says the island's secretary of state would become governor in the event of a resignation, but Secretary of State Luis Rivera Marin left the post due to the chat scandal. Next in line is Vazquez, whom many protesters reject because of her ties to the governor.

A string of Rossello's closest aides have stepped down as prosecutors investigated the scandal. The governor's chief of staff, Ricardo Llerandi, resigned on Tuesday, citing concerns for the safety of his family.