An undocumented immigrant who is facing deportation after he was detained while delivering pizza to a military base in Brooklyn will be allowed to stay in the country until at least July.

A federal judge on Saturday granted an emergency stay of the deportation of Pablo Villavicencio after the Legal Aid Society filed a petition for the stay in Manhattan federal court.

Judge Alison Nathan granted the stay, which will last until July 20.

Villavicencio will remain in the custody of U.S. Immigration and Customs Enforcement as he pursues permanent residency status.

Gov. Andrew Cuomo on Thursday offered the deliveryman and his family free legal help.

The Ecuador native was delivering pizza June 1 to the Fort Hamilton Army base, as he had many times before, when military police at the base asked for identification.

Villavicencio showed a New York City identification card, also known as IDNYC, as he had done during previous deliveries. This time, however, they rejected it.

The military police directed Villavicencio to get a day pass. The Army said he signed a waiver okaying a background check, and an active Immigration and Customs Enforcement warrant was discovered.

Immigration and Customs Enforcement officials said the military police officers at the base then detained Villavicencio and turned him over to federal immigration officials.

Villavicencio, the father of two little girls who were born in the United States, came to the U.S. a decade ago. He got married to Sandra Chica, a U.S. citizen, eight years ago and had filed an application for citizenship.

"It's cruel," Sandra Chica, the man's wife, said at a press conference Wednesday. "They're going to separate my daughters from him. He was supporting the family. Now, I'm going to be by myself, along with two kids. I heard that he's going to be deported next week."

Villavicencio was granted voluntary departure by an immigration judge in March of 2010 but failed to leave the country by that July. As a result, his voluntary departure order became a final order of removal, Immigration and Customs Enforcement said.

Elected officials joined Villavicencio's wife and two young daughters for the press conference outside Fort Hamilton on Wednesday, slamming the delivery man's detention.

"He was a tax-payer, contributor to our community entering this base, and now he went from being in this base — that's here to protect us — to prison," Brooklyn Borough President Eric Adams said.

"Does the Army now have some new policy that demands all non-military personnel show proof of citizenship to gain access onto the Army base?" Brooklyn City Councilman Justin Brannan said. "Otherwise, what happened here? Is this part of some new Donald Trump deportation strategy?"

Sandra Chica said she has no other family in New York. She has set up a GoFundMe page for support for the couple's daughters.

Republican Rep. Dan Donovan, whose district includes the base, called criticism of the arrest "just more insanity."

Mayor Bill de Blasio, meanwhile, said, "Overbroad enforcement against immigrant New Yorkers does nothing to make us safer."

Cuomo has asked federal homeland security officials to look into the case, saying recent detentions raise significant legal questions.