Former New York City Mayor Rudy Giuliani says President Trump tasked him with coming up with a way to legally implement his controversial executive order banning immigration from seven predominantly Muslim countries.

“I’ll tell you the whole history of it,” Giuliani said in an interview with Fox News’ Jeanine Pirro on Saturday night. “When he first announced it, he said ‘Muslim ban.’ He called me up. He said, ‘Put a commission together. Show me the right way to do it legally.'”

Slideshow: Anti-Trump protesters rally for Muslim and immigrant rights >>>

Giuliani, a former U.S. attorney, said he consulted with U.S. Reps. Mike McCaul, R-Texas, and Peter King, R-N.Y., and “a group of very expert lawyers” on the plan.

“And what we did was, we focused on — instead of religion, danger,” Giuliani said. “The areas of the world that create danger for us. Which is a factual basis, not a religious basis. Perfectly legal, perfectly sensible. And that’s what the ban is based on.”

Giuliani and Trump head into a meeting in November. (Drew Angerer/Getty Images)

On Friday, Trump signed an executive order barring people from seven countries — Syria, Sudan, Yemen, Iran, Iraq, Libya and Somalia — from entering the United States for 90 days. It also stopped all refugees from entering the U.S. for 120 days and indefinitely suspended the entry of refugees from Syria.

During his presidential bid, Trump called for a “total and complete shutdown of Muslims” entering the United States. That proposal subsequently evolved into a vague promise of “extreme vetting,” with the help of Giuliani.

“I think it’s a good idea to tighten the vetting process,” Senate Majority Leader Mitch McConnell said on ABC’s “This Week” on Sunday. “But I also think it’s important to remember that some of our best sources in the war against radical Islamic terrorism are Muslims, both in this country and overseas.

“I think we need to be careful,” McConnell added. “We don’t have religious tests in this country.”

Trump and Giuliani in October. (Jonathan Ernst/Reuters)

The Trump administration insists the ban doesn’t constitute one.

Story continues

“It’s not based on religion,” Giuliani said. “It’s based on places where there is substantial evidence that people are sending terrorists into our country.”

“It’s not a Muslim ban, but we were totally prepared,” Trump said while speaking to reporters in the Oval Office on Saturday. “It’s working out very nicely. You see it at the airports, you see it all over.”

On Saturday night, a federal judge in Brooklyn issued an emergency stay temporarily halting the removal of immigrants and refugees detained following Trump’s order.

The decision came after the American Civil Liberties Union and other activist groups filed a class action lawsuit on behalf of two Iraqis who were held at New York City’s John F. Kennedy International Airport.

Related: Protests at U.S. airports over travel ban

“There is imminent danger that, absent the stay of removal, there will be substantial and irreparable injury to refugees, visa holders, and other individuals from nations subject to [Trump’s] executive order,” Judge Ann Donnelly said in her ruling.

“President Trump’s executive order is simply un-American,” New York City Mayor Bill de Blasio said on CNN’s “State of the Union” Sunday. “It is suggesting that people’s civil liberties can be taken away, even if they are green card holders, even if they’re permanent residents on the pathway to citizenship. … It makes no distinction if someone has a green card and is already recognized on the pathway to citizenship. It makes no distinction if you have served in the U.S. military previously. You still can be detained. In this country, the notion of detention without due process, without probable cause or a charge against you, violates our constitutional norms.”

Slideshow: Protests against Trump’s travel ban hit the streets of NYC >>>

But Giuliani, who currently serves as a White House cybersecurity adviser, said the ban is simply an example of Trump “negotiating in the best interests of the United States of America — not the rest of the world.”

Read more from Yahoo News: