Pablo Villavicencio, 35, was arrested by the military police in Fort Hamilton in June when he was carrying an order from the brick oven pizza restaurant in Queens where he worked. He was handed over to the Immigration and Customs Authority.
He was released Thursday night from the Hudson County Correctional Center in Kearny, New Jersey.
"Thanks, thanks for everything," he said. "I'm so happy."
The Legal Aid Society, an organization providing legal assistance to those in need, said a judge in the southern district of New York issued an injunction on Tuesday.
"Today is also a confirmation that the courts can still serve as a control for the (US) executive (branch) if it breaks our laws and principles," said Adriene Holder, a lawyer in the department for Civil Practice at The Legal Aid Society. "The Villavicencio family has finally gotten a decisive relief from their 53-day nightmare and we will continue to fight with them to protect their right to remain in the community they call home."
Villavicencio's potential deportation had triggered a national reaction, along with fear in immigrant communities.
Villavicencio, a native of Ecuador, submitted his Green Card in February, waiting for an answer he was detained, His wife Sandra Chica said.
Chica is a US citizen and they have two young daughters who were born in the United States.
"Mr. Villavicencio was held for 53 days is 53 days too long – that should never have happened," said Governor Andrew Cuomo. "As the federal government continues its un-American attack on immigrants, New York will stand with our immigrant communities and seek to uphold the values of the (Statue of Liberty)."
On the day of his arrest, Villavicencio tried to deliver a pizza to the base of the Fort Hamilton Army in Brooklyn. He showed his ID in New York City to a guard, as he had done several times before, but the base said in a statement that he did not have the proper ID, so he had to get a daily visitor badge.
Villavicencio ended with the signing of an exemption, an active arrest warrant resulted in his deportation and led the military police to call immigration officers.
The judge ruled Tuesday that Villavicencio, who had come illegally into the country in 2008, has the right to pursue a legal waiver to block his deportation order.
Judge Paul Crotty said that Villavicencio, apart from his immigration violations, was an "exemplary citizen". Villavicencio has no criminal history.
The verdict follows at the beginning of this month, which temporarily postponed his deportation.
CNN's Yilber Vega, Amir Vera and Polo Sandoval contributed to this report.