A fugitive pedophile opened fire on officers in a Greenwich Village smoke shop Monday, wounding an NYPD detective and two US marshals before they shot him dead.

Authorities tracked Charles Mozdir — who had been on the lam since 2012 — to the West Fourth Street store after his girlfriend dropped a dime on him, sources told The Post.

The woman saw a segment about the child molester on John Walsh’s TV show “The Hunt’’ on Sunday night — and was so disgusted that she contacted authorities and gave them his cellphone number, they said.

Investigators narrowed down his phone’s “pings’’ to the heart of the Village, and a New York-New Jersey Regional Fugitive Task Force member spotted Mozdir on Monday afternoon.

Mozdir, 32, was working behind the counter of the bong-peddling Smoking Culture NYC store at 177 W. Fourth St. at around 1:10 p.m. when the officers rushed in.

But the tattooed pervert — who had grown long hair and a beard to disguise himself — pulled out his .32-caliber revolver and shot at them, cops said.

He got off about four rounds, hitting newly minted Detective Mario Muniz twice in his bulletproof vest and once below it, in his lower abdomen. The vest saved the life of the 45-year-old Queens dad of three.

“I heard the screaming,’’ said tattoo artist Dong Hwan Kim, 30, who works nearby. “[The detective] came out holding his belly. Other guys were holding it, too.”

The two US marshals, Pat Lin and Ryan Westfield, 34, also were wounded — one in his elbow, the other in his buttocks.

But they still got off about 10 shots at Mozdir, hitting him seven or eight times and killing him.

“I was in my apartment, and I heard, ‘Bang! Bang! Bang!’ ” said an 85-year-old building resident who gave only his first name, Leo.

“I said, ‘Gee, it’s late for the Fourth of July.’ ”

Michael Brandow, 54, a writer who lives above The Slaughtered Lamb pub across the street, heard cops yelling, “Get off the street!’’

“I thought it was a movie or ‘NYPD Blue,’ ’’ he said. “It kinda made me sick when I realized it wasn’t a TV show.”

Mozdir was ready to kill.

“He had 20 additional rounds of ammunition in his pocket,” said NYPD Commissioner Bill Bratton at Bellevue Hospital, after visiting the wounded officers.

One bullet caused serious injury to Muniz, who needed surgery Monday night but still managed to speak afterward to his mother, Carmen.

“I told him I love him, I love him — and he said he loved me too,” she said of their conversation at Bellevue. “He’s stable, and the doctors all said he is doing great.”

She said her son, the father of two boys and a girl, had been helping care for her since she suffered a heart attack.

“As a mother, I was always afraid of something happening,” she said.

Westfield’s neighbors in Livingston, NJ, said they were pulling for the hero, whom they often see walking his two boxers.

“We hope he’s home soon,” said next-door neighbor Grace Marinello, 61.

Mozdir had been the target of a nationwide manhunt after a family friend accused him of molesting her son while the child lay sick in bed in Coronado, California, in June 2012.

It was the second such case against him, investigators said, and they discovered child porn and bestiality videos in his home.

They found his vehicle abandoned, its license plates ripped off and a container of gas inside, in Darien, Georgia, later that June.

Acting on a tip that he might have fled to Mexico, authorities searched Baja California but found nothing.

They knew he had extensive search-and-rescue training, was capable of living off the land and was familiar with firearms. He had at least one gun registered to him and another in his possession.

It turned out he had been hiding in Key West, Florida. He moved to Manhattan months ago, sources said.

Authorities got a tip that he was working in a restaurant in New York after CNN’s “The Hunt” aired an episode about him on July 20, sources said. But the lead went nowhere.

The show then aired the episode again Sunday, and afterward, Mozdir’s gal pal called authorities.

Mozdir had gone from a clean-cut, baby-faced man to a grizzly, long-haired oaf, and by the time the task force found him, “he looked nothing like his picture on TV,’’ a source said.

An undercover cop spotted him in the store, then called for backup before trying to nab him.

Three teenage girls said they saw Mozdir last week staring at them as they waited on line to get into a local swimming pool. He was wearing Army fatigue pants, a white T-shirt and dark glasses, they said.

“He just stopped and stared with his hands in his pockets,” said Shavonnie Moorer, 16.

Her friend Laneasia Holmes, also 16, added, “We were really scared until we went inside.”

But a neighbor who frequents the shop described Mozdir as seemingly “a good person,” adding, “He always said hi to me, and when I brought my daughter in, he’d say hi to her.”

Additional reporting by Kate Sheehy, Antonio Antenucci, Kathleen Culliton, Frank Rosario and Kirstan Conley