A pizza deliveryman made a run to a Brooklyn Army base — where officials took the grub and then handed him over to immigration agents for deportation.

Pablo Villavicencio, an undocumented immigrant from Ecuador who lives on Long Island with his American wife and kids, says he went to the Fort Hamilton base Friday to deliver an order of pasta to a sergeant — flashing his city-issued IDNYC card for entry, as he has done before.

But once inside, Villavicencio says another guard demanded more identification — and officials called US Immigration and Customs Enforcement when he came up empty-handed.

“There was a different security guard and he told me I needed to go get another pass to enter . . . A tall man with dark skin started to ask me many questions, he asked me about why I didn’t have any Social Security card,” Villavicencio told The Post by phone from immigration detention.

“He called the NYPD and the NYPD told him I didn’t have any record, that I was clean. But the man said, ‘I don’t care.’ He said I need to keep waiting and he called ICE.”

The spaghetti-loving sarge, to whom Villavicencio has delivered before with no problem, came to his defense, to no avail.

“The sergeant was telling the man … he had no business calling ICE, he just has to verify I had no problems and let [me] through,” Villavicencio said.

A Fort Hamilton spokeswoman says Villavicencio was directed to obtain a pass when he couldn’t produce a proper ID — but when he signed a waiver for a background check, “an active [ICE] warrant was discovered.”

An agency spokeswoman said Villavicencio has been an “ICE fugitive” since 2010, when he failed to comply with a voluntary departure order.

He’s been married to a US citizen five years and they have two young daughters. He applied for a green card in February — but is now slated for deportation within days.

“It’s cruel that they’re going to separate my daughters from him. He’s supporting the family and now I’m going to be by myself with them,” said his wife, Sandra Chica, 38, weeping.

A regular at Nonna Delia’s restaurant in College Point, Queens, where Villavicencio has worked for nine months, said the arrest left fellow employees “hurting.”

“He’s a really good guy,” said Cyrus Zavieh, 48, a professional clown whom Villavicencio booked to perform at his daughter’s birthday party next month.

“He’s gone there before for deliveries and it’s never been an issue or problem. ”

Gregory Dragonetti, 50, manager of Campania Pizza near the base, says his workers all go through a military background check to get a pass that allows them in; otherwise, they’d need two forms of ID.

But a worker at Nonno’s Pizza on Third Avenue in Bay Ridge, right near the base, said delivery guys either simply show their driver’s license or drop off food at the gate.

“I’m surprised . . . They’re always nice to us and they order a lot from here,” said Tony Rodriguez.

A Pentagon spokesman noted there has been no policy change, but said the base commander might have tightened screening.

Councilman Justin Brannan (D-Bay Ridge) demanded Villavicencio’s release. “Is our city or our nation any safer now that Pablo the pizza deliveryman is off the streets? It’s insane — the message it sends is scary and ridiculous,” he said.

But Rep. Dan Donovan (R-SI, Brooklyn) said, “Liberal activists are attacking ICE agents and military personnel for following the law in detaining an immigrant reportedly here illegally.”

Additional reporting by Marisa Schultz