Puerto Rico’s embattled Gov. Ricardo Rosselló announced on Wednesday he will resign from office amid mass protests on the island after offensive text messages between him and members of his administration leaked to the press.

In a Facebook video released just before midnight, Rosselló announced he would step down effective Aug. 2.

He’ll be the first governor to resign in the modern history of ­Puerto Rico. Justice Secretary Wanda Vázquez is expected to take the post.

“The demands have been overwhelming and I’ve received them with the highest degree of humility,” Rosselló said in his resignation message.

In the messages leaked to the press, Rosselló called former New York City Council Speaker Melissa Mark-Viverito, who is from Puerto Rico, a “whore” in Spanish. He has since apologized.

Rosselló’s chief fiscal officer, Christian Sobrino Vega, wrote in another message that Ricky Martin, the island’s gay superstar singer, “is such a male chauvinist that he f—ks men because women don’t measure up.”

The messages drew outrage from Puerto Ricans, who formed mass protests in the streets of San Juan, calling for Rosselló’s resignation.

The island is also reeling from damage caused by Hurricane Maria two years ago and a recession that has stretched for more than a decade.

Earlier Wednesday, the island’s legislature began an impeachment process against Rosselló, a senior lawmaker announced.

Johnny Mendez, the speaker of Puerto Rico’s House of Representatives, said the process began when a probe into the leaked messages found that crimes may have been committed during the group chats.

An independent panel of lawyers commissioned by Mendez found that four felonies and one misdemeanor may have been committed during the group chats, said one attorney, who didn’t specify the crimes.

With Post wires