A federal judge delivered a stunning rebuke to the Affordable Care Act late Friday, ruling the individual mandate is unconstitutional and nullifying the entire ACA in a case brought by 20 Republican state attorneys general.

President Donald Trump celebrated the ruling immediately, saying on Twitter, "As I predicted all along, Obamacare has been struck down as an UNCONSTITUTIONAL disaster!"

The president spent much of his first year in office attempting to repeal the ACA, known informally as Obamacare for its proponent in the White House before Trump. The last Republican-led health care bill was defeated in July 2017 when the late Sen. John McCain voted against it.

The president also implored Senate Majority Leader Mitch McConnell and soon-to-be House Speaker Nancy Pelosi to work out a new health care bill.

The law will remain in place for now as the appeal process continues, a fact acknowledged by White House press secretary Sarah Sanders, even as the executive branch took a victory lap.

"Obamacare has been struck down by a highly respected judge. The judge’s decision vindicates President Trump’s position that Obamacare is unconstitutional," Sanders said in a White House statement. "Once again, the President calls on Congress to replace Obamacare and act to protect people with preexisting conditions and provide Americans with quality affordable healthcare. We expect this ruling will be appealed to the Supreme Court. Pending the appeal process, the law remains in place."

District Court Judge Reed O'Connor of Texas wrote in his decision, "Sometimes, a court must determine whether the Constitution grants Congress the power it asserts and what results if it does not. If a party shows that a policymaker exceeded the authority granted it by the Constitution, the fruit of that unauthorized action cannot stand."

O'Connor ruled, in the 55-page document, "The Court finds that both plain text and Supreme Court precedent dictate that the Individual Mandate is unconstitutional under either provision."

As cited by the judge, the Supreme Court previously ruled that the individual mandate of the ACA, while not permissible under the Interstate Commerce Clause, was constitutionally permissible under Congress's tax power because it required a "shared-responsibility payment."

O'Connor explained in his ruling that by passing the Tax Cuts and Jobs Act of 2017 -- pushed by Republicans, signed last December by Trump and including a rollback of the individual mandate -- Congress reduced the ACA's shared-responsibility payment to zero, effective Jan. 1, 2019. Because the shared-responsibility payment will no longer collect revenue, in the Court's view, it is no longer considered a tax, and thus unconstitutional.

The response from Democrats was immediate and forceful as well. Pelosi called the ruling "absurd" and said it would be appealed.

"Tonight's district court ruling exposes the monstrous endgame of Republicans' all-out assault on people with pre-existing conditions and Americans' access to affordable health care," Pelosi said in a statement.

"While the district court's absurd ruling will be immediately appealed, Republicans are fully responsible for this cruel decision and for the fear they have struck into millions of families across America who are now in danger of losing their health coverage," the statement continued. "When House Democrats take the gavel, the House of Representatives will move swiftly to formally intervene in the appeals process to uphold the life-saving protections for people with pre-existing conditions and reject Republicans' effort to destroy the Affordable Care Act."

Pelosi is expected to take over as House speaker in January when Democrats regain control of the House in the wake of the midterm elections. In the Senate, where Republicans maintained control, Minority Leader Chuck Schumer backed up Pelosi's condemnation.

"The ruling seems to be based on faulty legal reasoning and hopefully it will be overturned. Americans who care about working families must do all they can to prevent this district court ruling from becoming law," Schumer wrote in a statement.

The ruling throws a wrench into the plans of people who rely on Obamacare -- or who have uncertain insurance coverage and a pre-existing condition. The final day for Obamacare signups in many states is Saturday.

While Trump has promised to protect people with pre-existing conditions, it's up to Congress to enact an Obamacare alternative if the courts strike down ACA.

If the appeals court -- and Supreme Court -- uphold Friday night's ruling, it could translate into an abrupt and disruptive turn in the health care of millions of Americans. For the 2018 coverage year, 8.8 million people signed up for a plan on Healthcare.gov.

In October, Health and Human Services Secretary Alex Azar -- who supported the lawsuit -- spoke to ABC News about the administration's "plan B" to protect people with pre-existing conditions if the courts shut down Obamacare.

"The president has been 100 percent clear: He will not sign a repeal-and-replace package for Obamacare that does not adequately protect individuals who have preexisting conditions," Azar said. "There are many ways to do that, but he will not sign any package that does not protect people with pre-existing conditions."

Despite that assurance, Trump last year was eager to sign Republican legislation to repeal Obamacare that independent analysts said would have weakened protections for people with pre-existing conditions by allowing insurers to potentially charge sick people more.

ABC News' Mariam Khan contributed to this report.