Inside a handsome brick building on a tree-lined street near Brooklyn’s Prospect Park lay one of the city’s dirtiest secrets.

As people strolled past the Prospect Heights home on their way to the park, the Brooklyn Museum or a bar where celebrated authors give readings for The New Yorker crowd, two 16-year-old girls were allegedly being kept inside as sex slaves.

For one harrowing month last year, the teens’ captors forced them to strip to their underwear, pose for Backpage.com ads and have sex with up to 10 johns a day, prosecutors charge.

The girls were saved when one of them escaped in July and ran to police. But they are just two of the thousands of sex slaves being trafficked under the noses of New York City residents every day, part of a silent epidemic that law enforcement is struggling to contain.

“This is going on everywhere. Down the street, in the rich neighborhood, the poor — whether you’re white, yellow, green, blue. It cuts across different ethnicities, religious backgrounds, economic backgrounds,” Laura Riso, an FBI victims specialist in New York City, tells The Post.

“It’s enormous.”

Last year, the NYPD rescued one person a week from sex slavery and busted 228 pimps while working 265 sex trafficking cases — more than double the number in 2016.

But officials know they’re just scraping the surface.

“Trafficking is a bigger problem” than what the numbers show, says Inspector Jim Klein, commander of the NYPD’s Vice Enforcement Unit and a 36-year department veteran.

“I have 200-and-however-many pimps I’ve locked up. On average, a pimp is going to have at least four or five women, girls, that he’s going to be working. [And] I haven’t locked up every pimp.

“It’s modern-day slavery.”

Through interviews with top law enforcement officials, prosecutors, advocates and victims from around the five boroughs, The Post has pieced together a picture of New York’s sex-slavery underbelly — and the struggle to end it.

“People are shocked to hear that it actually exists in New York City,” says Manhattan District Attorney Cyrus Vance Jr.

“This is not a case where you have super-high-priced, fancy sex businesses — this is really disgusting, forced, cruel, cold. Taking kids who are in need of help, preying upon that need, developing a relationship and then turning against them and turning them into kids who are making money for them on the street — those are the cases that we get.”

Thanks to Hollywood films such as “Taken,” people who hear the term “sex trafficking” often think of a sorority girl kidnapped and chained to a radiator by men with foreign accents.

But the average victim is a vulnerable girl from a troubled home who has already been sexually abused and is first sold for sex as young as 12.

The girls often aren’t detained at gunpoint — not at first, anyway — but are instead manipulated into “the life” by smooth-talking pimps promising a better life.

Some are even dazzled by glamorized portrayals of prostitutes in songs, movies and books — like a 14-year-old girl who told Queens prosecutors she had been inspired to turn tricks by the 2005 Snoop Dogg film “Boss’n Up.”

“Her aspiration was for [her pimp] to fall in love with her if she made enough money,” says Queens Assistant District Attorney Jessica Melton, chief of the Human Trafficking Unit.

Many local victims come from in or around the city, but others are bused into the Big Apple from upstate or nearby states such as Pennsylvania and Connecticut.

There also are the women and girls brought here from overseas and forced to work in an estimated 700 illicit “massage” parlors across the city.

Of course, there are adults who choose to become escorts. But police say they’re the minority.

“I can confidently say the majority — the overwhelming majority — of people engaging in sex for money are doing it against their will,” says Klein, who has run the vice unit for the last two years.

“There’s no cookie-cutter pimp,” Klein says.

Some are gang members or drug dealers hunting new revenue streams. Others are just teenagers themselves and from a family of traffickers. They’re men and women, white, black, Asian and Hispanic.

But all traffickers have made the same sick calculation.

“You can sell a gun once, right? You could sell a kilo of coke once . . . But once it’s gone, it’s gone,” Klein says. “But a woman or a person, that’s 15 times a day every day . . . for as many years as you possibly get out of that person. That’s a never-ending cycle.”

The pimps often sweet-talk the girls into joining them, but once their victims realize the glamorous life they were promised is anything but, that’s when things turn violent.

“One guy kept [a girl] in a dog cage because she wasn’t cooperating,” Klein says.

A 17-year-old girl trafficked by convicted Queens pimp Ricardi “Dirty” Dumervil escaped only to be kidnapped again, burned with cigarettes and bashed with a gun before being dragged to Atlantic City to keep working, according to Melton.

‘This is not a case where you have super-high-priced, fancy sex businesses — this is really disgusting, forced, cruel, cold. Taking kids who are in need of help, preying upon that need, developing a relationship and then turning against them.’ - Cyrus Vance Jr.

And the 14-year-old who watched the Snoop Dogg film? She was found locked in a closet surrounded by pots of urine.

These thugs aren’t just operating out of decrepit buildings in the worst parts of town, and their victims aren’t necessarily kept locked up.

“It happens right under our noses . . . This is something that could be happening right in our neighborhoods,” says Juanito Vargas, vice president of the victim-assistance nonprofit Safe Horizon.

“You go to the deli in your neighborhood and are served your morning coffee by someone, and you don’t know if that person is being trafficked,” he says.

There was the Prospect Heights apartment where those two 16-year-olds were allegedly forced to turn tricks in fear for their lives by a trio of 20-somethings.

There was a Bronx homeless shelter just blocks from Yankee Stadium where convicted sex trafficker Maria Soly Almonte repeatedly prostituted out three of her sisters and a 13-year-old girl.

When she wasn’t turning tricks, the 13-year-old attended eighth grade at PS 29 — where the school nurse figured out what was going on when the girl came in weekly requesting STD and pregnancy tests.

At a Howard Johnson hotel in Brownsville, Brooklyn, a couple allegedly forced two 14-year-old runaways to have sex with man after man and give up all their earnings.

And at a Manhattan youth shelter, kids escaping broken homes were lured into a life of prostitution with offers of booze, cash and a warm bed — lured by ads posted openly on Craigslist.

“Are you a female that wants to stop living in Covenant House?” it read, alongside photos of tequila and hundred-dollar bills.

When the 14-year-old Snoop Dogg fan was rescued from the closet, she first told police and prosecutors that she wanted to be in there, Melton says.

It’s a prime example of why it’s so hard for police to catch and convict traffickers: The women and girls often don’t see themselves as victims.

Making matters worse, antiquated state laws don’t recognize underage prostitutes as victims of trafficking, either, unless there is clear force or coercion, so their cooperation is often crucial.

With limited resources for survivors, it’s a tough sell.

“We’ve had girls say, ‘At least I have a place to sleep — yeah, he beats me, but at least . . . I’m not sleeping in the gutter,’ ” says David Weiss, a senior assistant district attorney in Brooklyn.

Meanwhile, immigrants working in massage parlors often also fear deportation and are typically trafficked by members of their own communities.

“They are so hard to crack,” says Assistant District Attorney Laura Edidin, head of the Brooklyn prosecutor’s Human Trafficking Unit. “Both because the way in which money is moved out of massage parlors is sophisticated and because women who are being exploited in those massage parlors are very unlikely to come forward.”

And most NYPD cops simply aren’t trained to deal with the survivors, critics say.

“I had to stand in a hospital with a rape victim and nearly got myself arrested with these huge cops towering over her, demanding answers,” says Rachel Lloyd, founder of the anti-trafficking organization GEMS and a survivor of trafficking herself.

Just recently, glaring staffing and training issues with the NYPD’s Special Victims Division — whose cops sometimes have first contact with trafficking victims — were exposed in a scathing report by the city Department of Investigation.

Still, police and prosecutors say they’ve made huge strides in recent years against sex trafficking.

District attorneys now have dedicated units for tackling trafficking, more citizens are calling the NYPD tip line, and law enforcement is actively working with nonprofits to find and help the victims.

Last year, the NYPD announced that it had added 25 detectives to the vice unit and formed a joint task force with the FBI.

The department has also shifted its focus to busting pimps and johns rather than prostitutes.

“It is an overwhelming problem; it can feel that way,” says Manhattan Assistant District Attorney Carolina Holderness, chief of the borough’s Human Trafficking Response Unit. “We’re just trying to hit it with everything we have.”

Lloyd adds, “When you take a long view, there’s been significant progress.”

Still, she says, “when you take the immediate view, good grief, there are so many gaps and so many ways we are failing our kids.”