Mayor Bill de Blasio ventured into the city’s decrepit subway system Sunday — but didn’t have to face the foul-smelling and often crazy vagrants whom ordinary New Yorkers are forced to contend with every day.

That’s because police were ordered to roust all the homeless people from two stations ahead of the mayor’s four-stop press event as he rode from his Park Slope gym to his new re-election headquarters in downtown Brooklyn, law enforcement sources told The Post.

The rank and file had until 11 a.m. to prepare the Fourth Avenue/Ninth Street and Jay Street/MetroTech F train stations for the mayor’s brief, underground publicity stunt, sources said.

One source characterized the directive — contained in an email from the NYPD’s Transit Bureau — as instructing cops to “make sure nobody’s hanging out” so that the stations “looked nice.”

Another source said the mayor’s office notified police brass of his schedule ahead of time “with the expectation that the subway stations would be free and clear of homeless people.”

“It’s too bad he’s only interested when he’s going to get on the subway,” the source said.

“I wish he had the same attention to detail when he wasn’t on the subway. Too bad he doesn’t care about quality of life for all passengers and not just himself.”

A newsstand manager inside the Jay Street/MetroTech station was shocked by the noticeable absence of derelicts on the uptown A, C and F platform surrounding his kiosk.

“I see a lot of homeless people in a week — up to 25. On average five a day. Today, I have seen only one,” Ali Imtiaz said.

“I was asking my colleague today why we don’t see any homeless.”

Imtiaz also said he spotted a group of cops — “more than four of them” — stroll past his business around 10 a.m., and lamented that it didn’t happen more often.

“It’s good for everybody that they clear out the homeless,” he said. “This should be continued. This is a very busy subway.”

De Blasio’s presumptive Republican challenger, Staten Island Assemblywoman Nicole Malliotakis, blasted the arbitrary crackdown.

“For someone who claims to care about the most poor New Yorkers, to have someone clear his path when he’s about to board the subway … tells you all you need to know about Mayor de Blasio,” she said.

“These are fellow New Yorkers who are sleeping in the street, sleeping in the subway. The mayor just doesn’t care.”

Gene Russianoff, of the Straphangers Campaign, blasted the temporary removal of the homeless.

“The optics are terrible,” he said. “It looks like they don’t want them to intrude on a movie set.”

A City Hall spokesman denied that any vagrants were kicked out of the stations, and said that “these sources are refusing to provide their names because what they are saying is not true.”

De Blasio press secretary Eric Phillips also noted that “the mayor had a few-minute chat with a homeless person” upon emerging from the subway.

It was not clear if the man, who complained to Hizzoner over conditions in the city’s shelters, had been booted from the train station.

De Blasio’s F-train ride marked his latest foray underground amid an escalating feud with Gov. Andrew Cuomo over funding for the crumbling mass transit system.

Following a trip in a motorcade of SUVs from Gracie Mansion for a workout at the Prospect Park YMCA, the mayor used a MetroCard to swipe himself and wife Chirlane McCray through a turnstile at the Fourth Avenue/Ninth Street station.

Once aboard, Hizzoner — who was joined by a pack of journalists — launched into a diatribe against Cuomo and MTA Chairman Joe Lhota, who last week blamed de Blasio for refusing to spend the city’s $4 billion-plus budget surplus to fix the subways.

“Here’s the truth: They’re not even spending their capital budget,” the mayor said. “There’s a huge amount of money sitting there, including the money the city gave. We gave them $2.5 billion a couple of years ago. Almost 90 percent of that money is just sitting there.”

De Blasio vowed not to allocate any more funds, saying the state “has used the MTA as a piggy bank” by taking “almost half a billion dollars in money out of the MTA to use for the state budget.

“The governor and Chairman Lhota simply need to get in front of everyone [and] say, ‘We’re fully responsible, we have to fix the problem.’ They have the resources.”

Lhota called the mayor’s remarks “completely disingenuous” given the planned release of the chairman’s “30-day overhaul plan” for the subways later this week.

“What we need is leadership, not photo ops,” Lhota said.

Cuomo’s office didn’t return a request for comment.