An undercover TSA inspector with an improvised explosive device stuffed in his pants got past two security screenings at Newark Airport — including a pat-down — and was cleared to get on board a commercial flight, sources told The Post yesterday.

The breach took place Feb. 25, when the Transportation Security Administration’s special operations team — the agency’s version of internal affairs — staged a mock intrusion at the airport.

“This episode once again demonstrates how Newark Airport is the Ground Zero of TSA failures,” a source said.

The “bomber” was part of the four-person “Red Team” that posed as ticketed passengers and filed through the B1 checkpoint of Terminal B — home of American Airlines, JetBlue and Delta, sources said.

With the inert “bomb” stashed somewhere in his pants, he got through the magnetometer undetected at around 11 a.m. He was then pulled aside for a physical screening, and a TSA agent failed to discover the IED and allowed the “bomber” to go to his gate.

“He did have a simulated IED in his pants,” the source said. “They did not find it.”

The exact makeup of the mock IED was not available, but even devices small enough to be stashed in a passenger’s pants could blow a hole through a plane’s fuselage.

TSA inspectors have previously used mock bombs modeled after devices used by 2009 “underwear bomber” Umar Farouk Abdulmutallab and 2001 “shoe bomber” Richard Reid.

Only one member of the TSA’s terror team was stopped at the checkpoint — a female agent “carrying a simulated IED inside her carry-on that was inside a child’s doll,” the source said.

It had “wires sticking out” and was obviously suspicious and she was pulled aside, sources say.

The Red Team also targeted Terminal C the same day, although results from that test were unclear.

The TSA said in a statement that it would not provide details of any of its undercover operations.

“TSA regularly conducts covert testing of security layers. Regardless of the tests’ outcome, TSA officers are provided with immediate on-the-spot feedback so they receive the maximum training value that the drills offer,” the statement said.

“Due to the security-sensitive nature of the tests, TSA does not publicly share details about how they are conducted, what specifically is tested or the outcomes.”

Newark Airport, which has 1,400 screeners and supervisors, has long struggled with security.

Last year, 52 baggage and traveler screeners were fired and another 19 disciplined for major security lapses and thefts.

Newark Airport was where a screener left a note saying, “Get your freak on, girl,” after finding a vibrator in the bag of a Manhattan attorney in 2011.

And it was where, in 2010, an airport “Romeo” was able to walk unticketed and unscreened into a secure area so he could kiss his girlfriend goodbye.

Despite the security woes, the TSA this week declared it would soon allow travelers to carry non-locking knives up to 2.36 inches in length and a half-inch width onto airplanes.