Nearly two-thirds of the city apartments recently listed on Airbnb were being offered in violation of the law, an analysis by state authorities has found.

The study of data from the subletting service’s own Web site showed 64 percent of its 19,500-plus offerings for Jan. 31 covered an “entire apartment,” says an affidavit from the state Attorney General’s Office.

By law, a “permanent resident” must be present to sublet an apartment for fewer than 30 days.

In addition, more than 200 of the offerings came from just five “hosts,” suggesting third parties were renting out pads on behalf of their owners.

“The top five hosts by number of listings had the following number of listings: 80, 35, 31, 29 and 28,” Sumanta Ray, director of research and analysis for the AG’s Investor Protection Bureau, wrote in the affidavit, obtained by The Post.

The affidavit will be filed in court Monday by state AG Eric Schneiderman’s office, sources said. The AG is heading to court Tuesday to subpoena Airbnb records to identify users who are illegally renting out apartments.

New Jersey-based tech firm Connotate extracted the data from Airbnb’s site and put it in a spreadsheet for the Investor Protection Bureau. Ray analyzed it for the AG’s Office.

Court filings by the AG’s Office say Airbnb is fueling an underground industry of “illegal hotels” that has led to a surge in complaints about parties that leave “vomit and baggage strewn in hallways” and other problems.

Tom Cayler, chairman of the West Side Neighborhood Alliance’s Illegal Hotel Committee, railed at the online service.

“Airbnb has just become a scourge,” said Cayler, 63, of Hell’s Kitchen. “You’ve already got the sex industry using Airbnb. How long will it be before the gamblers and the drug dealers figure it out?”

“When you come home at night, you won’t know if you’ve got a trick, a poker game or a cocaine deal going on next door.”

Tenants advocate Bennett Baumer said a row of buildings on West 49th Street has been used as illegal hotels through Airbnb. At least three apartments there were cited by the city last year based on complaints.

A rep for the buildings’ owner did not respond to a request for comment Sunday.

Airbnb on Sunday said it boots users who abuse its service.

“The small group of bad actors that abused our platform aren’t part of the Airbnb community anymore, or they are on their way out the door, ” it said, adding most users “are regular New Yorkers just trying to make ends meet.”

Airbnb, which claims it will pump $768 million into New York’s economy this year, also noted, “Short-term rental laws were never meant to apply to New Yorkers occasionally renting out their own home.”