Just two days after getting shot while trying to arrest a suspected child molester in the West Village, NYPD Detective Mario Muniz was released from the hospital, with his partner as well as the U.S. marshal who also survived the gunfire by his side.

Muniz, 45, waved to dozens of applauding police officers from his wheelchair after being discharged from Bellevue Hospital Center Wednesday.

The bullet that struck Muniz, who has been in the department for more than 20 years, narrowly missed his small intestine, said Dr. Spiros Frangos, chief of trauma, emergency surgery and critical care at the hospital.

“I feel great,” Muniz said as he got into a waiting SUV, thanking the police, the hospital and his family. His partner, Detective Joseph Travato, pushed the wheelchair with U.S. Marshal Ryan Westfield standing right behind.

Muniz, along with the two marshals, were wounded Monday while trying to arrest Charles Mozdir, an alleged sex offender from the San Diego area. Mozdir, 32, was shot and killed during the shootout at about 1 p.m. inside the Smoking Culture shop on West 4th Street, where he was working, Police Commissioner Bill Bratton said earlier this week.

During the exchange of gunfire, Westfield was shot in the elbow, police said. A second marshal, Patrick Lin, sustained a gunshot to his backside, police said. Both marshals were released from the hospital Tuesday.

Muniz was shot three times: twice in his in bulletproof vest near his lungs and once in his stomach, a few centimeters to the right of his belly button, Dr. Frangos said. The bullet traveled from the right side of his stomach to the left, just centimeters in front of his vital organs.

“He was very lucky,” Dr. Frangos said. “The vest stopped the bullets that could have potentially done a lot more damage. And the one bullet that did get through, he was very fortunate.”

While in the hospital, Muniz was visited by his mother, son and fiancé, Bratton said. And right before he was discharged, Muniz was able to walk around the room, Dr. Frangos said.

“He's actually in good spirits,” he said. “We're all very, very pleased with the outcome. He's going to have to take some time off and take it easy for a few weeks.”

Muniz’s survival of Monday’s “wild shootout” was “nothing short of a miracle,” said Michael Palladino, president of the Detectives’ Endowment Association, the detectives’ union.

“What a difference a few days makes,” he said. “His spirit is, amazingly, very upbeat. And of course once he goes home to recuperate the realization I am sure though the reality of what could have happened will set in.

“This could have turned out to be terrible,” Palladino added.

The city will take care of Muniz’s medical bills since he was shot in the line of duty, Palladino said.