Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A federal judge in Texas on Monday issued a preliminary injunction blocking the U.S. government from enacting President Barack Obama's executive order on immigration to defer deportations for up to 5 million undocumented immigrants.

U.S. District Judge Andrew S. Hanen of the Southern District of Texas temporarily blocked the federal government from implementing "any and all aspects" of the order, which protected millions of people in the country illegally from immediate deportation.

Hanen's ruling allows a lawsuit filed by Texas and 25 other states challenging Obama's executive order to go forward.

In a memorandum accompanying his order, Hanen wrote that the lawsuit should go forward and that without a preliminary injunction the states will "suffer irreparable harm in this case."

"The genie would be impossible to put back into the bottle," he wrote, adding that he agreed with the plaintiffs' argument that legalizing the presence of millions of people is a "virtually irreversible" action.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

In his ruling, Hanen said the Obama administration violated the Administrative Procedure Act.

The preliminary injunction applies to the Deferred Action for Parents of Americans and Lawful Permanent residents, better known as DAPA, and expansions to the Deferred Action for Childhood Arrivals, both of which Obama announced in November. DAPA, part of which was set to go into effect on Wednesday, would grant work permits and defer deportation for three years of undocumented immigrants who are both parents of U.S. citizens and who've been living in the U.S. since 2010.

"This decision is a victory for the rule of law in America and a crucial first step in reining in President Obama's lawlessness," Texas Attorney General Ken Paxton, who is leading the lawsuit against the Obama administration, said in a statement. "This injunction makes it clear that the president is not a law unto himself, and must work with our elected leaders in Congress and satisfy the courts in a fashion our Founding Fathers envisioned."

Texas Governor Greg Abbott added: "President Obama abdicated his responsibility to uphold the United States Constitution when he attempted to circumvent the laws passed by Congress via executive fiat, and Judge Hanen's decision rightly stops the president's overreach in its tracks."

The rule of law has been upheld- President Obama’s Executive Amnesty has been ruled unconstitutional. — Office of Gov Abbott (@GovAbbott) February 17, 2015

However, White House press secretary Josh Earnest said in a statement that "the Department of Justice, legal scholars, immigration experts, and the district court in Washington, D.C. have determined that the president's actions are well within his legal authority."

He added: "The district court's decision wrongly prevents these lawful, commonsense policies from taking effect and the Department of Justice has indicated that it will appeal that decision."

An appeal would be heard by the 5th U.S. Circuit Court of Appeals in New Orleans.

Joaquin Guerra, political director of Texas Organizing Project, called the ruling a "temporary setback." "We will continue getting immigrants ready to apply for administrative relief," he said in a statement.

Our response "Judge Hanen’s ruling is not permanent and we are confident that it will be repealed in a higher court." http://t.co/c1NbKOno7i — UnitedWeDream.org (@UNITEDWEDREAM) February 17, 2015

Hanen has been on the federal court since 2002 after being nominated by President George W. Bush.

Among those supporting Obama's executive order is a group of 12 mostly liberal states, including Washington and California, as well as the District of Columbia. They filed a motion with Hanen in support of Obama, arguing the directives will substantially benefit states and will further the public interest.

A group of law enforcement officials, including the Major Cities Chiefs Association and more than 20 police chiefs and sheriffs from across the country, also filed a motion in support, arguing the executive action will improve public safety by encouraging cooperation between police and individuals with concerns about their immigration status.

NBC News' Christopher Nelson and The Associated Press contributed to this report.