(CNN) A federal judge in Texas said on Friday that the Affordable Care Act's individual coverage mandate is unconstitutional and that the rest of the law therefore cannot stand.

Legal experts say the ruling won't immediately affect Americans' health coverage, and a group of states led by California is already vowing to appeal. But the invalidation of the landmark health care law popularly known as Obamacare throws into doubt the future of health coverage for millions of Americans on the Obamacare exchanges and in Medicaid expansion.

The ruling and expected appeal sets up another cliffhanger in which the fate of the law, which Republicans have unsuccessfully tried to repeal for years, will likely once again ultimately lie with the Supreme Court.

Chief Justice John Roberts cast the deciding vote leaving the law intact in 2012, but it's unclear how the justices will view this challenge, which centers on changes to the individual mandate that were baked into the 2017 tax reform.

President Donald Trump, who campaigned in 2016 on a promise to undo Obamacare, was thwarted in Congress last year by a lone vote from the late Arizona Republican Sen. John McCain.

Trump immediately tweeted in celebration on Friday and called on Congress to act.

"As I predicted all along, Obamacare has been struck down as an UNCONSTITUTIONAL disaster! Now Congress must pass a STRONG law that provides GREAT healthcare and protects pre-existing conditions. Mitch and Nancy, get it done!" Trump wrote.

He later added, "Wow, but not surprisingly, ObamaCare was just ruled UNCONSTITUTIONAL by a highly respected judge in Texas. Great news for America!"

On Saturday, Trump told reporters that if the decision is eventually upheld by the Supreme Court, "we will be sitting down with the Democrats" to "get great health care for our people."

"Let's say repeal and replace, handled a little bit differently, but it was a big, big victory by a highly respected judge," Trump said during a visit to Arlington National Cemetery.

Later Saturday, Obama took to Facebook to urge people to enroll in the program, writing in a post that Friday's ruling "can be a scary thing to hear, particularly if you or someone you care about has a pre-existing condition."

"As this decision makes its way through the courts, which will take months, if not years, the law remains in place and will likely stay that way," he wrote.

Democratic House leader Nancy Pelosi decried the ruling and suggested that the coming Democratic-led House will intervene in the case.

"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," Pelosi said in a statement released late Friday. "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."

Today, the law governs American health care.

More than 4 million people have already signed up for 2019 coverage on the exchanges, and millions more are expected to pick plans before open enrollment ends Saturday.

The ruling threatens to wipe away the Affordable Care Act's protections for those with pre-existing conditions, which became a focal point of the midterm elections and helped Democrats take the House.

In his opinion, District Judge Reed O'Connor said the "Individual Mandate can no longer be fairly read as an exercise of Congress's Tax Power and is still impermissible under the Interstate Commerce Clause—meaning the Individual Mandate is unconstitutional."

He also held that the individual mandate is "essential to and inseverable from the remainder of the ACA."

The case against the ACA was brought by 20 Republican state attorneys general and governors, as well as two individuals. It revolves around Congress effectively eliminating the individual mandate penalty by reducing it to $0 as part of the 2017 tax cut bill. The mandate requires nearly all Americans to get health insurance or pay a penalty.

The Republican coalition, led by Texas Attorney General Ken Paxton, is arguing that the change rendered the mandate itself unconstitutional. The states say that the voiding of the penalty, which takes effect next year, removes the legal underpinning the Supreme Court relied upon when it upheld the law in 2012 under Congress' tax power.

The Trump administration said in June that it would not defend several important provisions of Obamacare in court. It agreed that zeroing out the penalty renders the individual mandate unconstitutional but argued that invalidates only the law's protections of those with pre-existing conditions. These include banning insurers from denying people policies or charging them more based on their medical histories, as well as limiting coverage of the treatment they need.

But the administration maintained those parts of the law were severable and the rest of the Affordable Care Act could remain in place.

Professor Tim Jost, of Washington and Lee University, noted that O'Connor went further than the Trump administration had asked.

"The Trump administration only asked that the individual mandate and provisions protecting individuals with pre-existing conditions be invalidated, but O'Connor's order would invalidate many provisions of the Medicaid program, the Medicare program and other federal laws," he told CNN.

But Jost said the structure of the challenge and of O'Connor's ruling means that nothing will change right away.

"Judge O'Connor has declared the individual mandate unconstitutional and the rest of the Affordable Care Act invalid, but he has not blocked its continued operation," Jost said.

Because the administration would not defend the law, California, joined by 16 other Democratic states, stepped in. They argued that the mandate remains constitutional and that the rest of the law, in any event, can stand without it. Also, they said that eliminating Obamacare or the protections for those with pre-existing conditions would harm millions of Americans.

Appeal coming

California Attorney General Xavier Becerra called the ruling "an assault" and a spokesperson for his office indicated an appeal would be coming.

"Today's ruling is an assault on 133 million Americans with preexisting conditions, on the 20 million Americans who rely on the ACA's consumer protections for healthcare, on America's faithful progress toward affordable healthcare for all Americans," Becerra said in a statement. "The ACA has already survived more than 70 unsuccessful repeal attempts and withstood scrutiny in the Supreme Court."

American Medical Association president Barbara McAneny said the group will work with other groups in pursuing an appeal and reversal of the decision.

"Today's decision is an unfortunate step backward for our health system that is contrary to overwhelming public sentiment to preserve pre-existing condition protections and other policies that have extended health insurance coverage to millions of Americans," she said in a statement. "It will destabilize health insurance coverage by rolling back federal policy to 2009. No one wants to go back to the days of 20 percent of the population uninsured and fewer patient protections, but this decision will move us in that direction."

Meanwhile, Paxton applauded the ruling and said it represents a massive check on federal power.

"Today's ruling enjoining Obamacare halts an unconstitutional exertion of federal power over the American health care system while our multistate coalition lawsuit works its way through the courts," Paxton said in a staement. "Our lawsuit seeks to effectively repeal Obamacare, which will give President Trump and Congress the opportunity to replace the failed social experiment with a plan that ensures Texans and all Americans will again have greater choice about what health coverage they need and who will be their doctor."

Steve Vladeck, a CNN legal analyst and a law professor at the University of Texas School of Law, said he felt an appeal could be looked on favorably by the Supreme Court.

"The ruling relies on conclusions about who can bring this suit and about the impact of President Trump's tax bill that have been widely debunked by scholars from across the political spectrum," Vladeck said. "It will certainly generate headlines, and it may even be upheld by the conservative federal appeals court in Texas, but it's difficult to imagine that the Supreme Court—which has already turned away two challenges to the ACA—would agree with tonight's ruling."

Pre-existing conditions and the midterm fight

The lawsuit entered the spotlight during the midterm elections, helping propel many Democratic candidates to victory. Protecting those with pre-existing conditions became a central focus of the races. Some 58% of Americans said they trust Democrats more to continue the law's provisions, compared to 26% who chose Republicans, according to a Kaiser Family Foundation election tracking poll released in mid-October.

The consumer protections targeted by the administration are central to Obamacare and transformed the health insurance landscape. Their popularity is one of the main reasons GOP lawmakers had such difficulty repealing Obamacare last year.

"Guaranteed issue" requires insurers to offer coverage to everyone regardless of their medical history. Prior to the Affordable Care Act, insurers often rejected applicants who are or had been ill or offered them only limited coverage with high rates.

Under the law's community rating provision, insurers are not allowed to set premiums based on a person's health history. And the ban on excluding pre-existing conditions from coverage meant that insurers cannot refuse to pay for treatments because of a policyholder's medical background.

All these provisions meant millions of people with less-than-perfect health records could get comprehensive coverage. But they also have pushed up premiums for those who are young and healthy. This group would have likely been able to get less expensive policies that offered fewer benefits prior to Obamacare. That has put the measures in the crosshairs of Republicans seeking to repeal the law and lower premiums.

It's no wonder that politicians on both sides of the aisle promised to protect those with pre-existing conditions during the election. Three-quarters of Americans say that it is "very important" for the law to continue prohibiting health insurers from denying coverage because of medical histories, according to the Kaiser Family Foundation's September tracking poll -- 58% of Republicans feel the same way. And about the same share of Americans say it's "very important" that insurers continue to be barred from charging sick people more.