(Reuters) - A federal judge in Texas on Friday ruled the Affordable Care Act, commonly known as Obamacare, was unconstitutional based on its mandate requiring that people buy health insurance, a decision in a case that could reach the U.S. Supreme Court.

U.S. District Judge Reed O’Connor in Fort Worth agreed with a coalition of 20 states that a change in tax law last year eliminating a penalty for not having health insurance invalidated the entire Obamacare law.

The coalition of states challenging the law was led by Texas Attorney General Ken Paxton and Wisconsin Attorney General Brad Schimel, both Republicans.

Republicans have opposed the 2010 law - the signature domestic policy achievement of Republican President Donald Trump’s Democratic predecessor Barack Obama - since its inception and have repeatedly tried and failed to repeal it.

O’Connor ruled that under the logic of the landmark 2012 Supreme Court ruling that upheld the law, the individual mandate, which required that most Americans obtain health insurance or pay a tax, is now unconstitutional.

In the 2012 ruling, a majority of the justices concluded that the individual mandate unconstitutionally imposed a requirement that Americans buy insurance. However, a different majority held the mandate amounted to a constitutional tax penalty.

On Friday, O’Connor ruled that after Trump signed a $1.5 trillion tax bill passed by Congress last year that eliminated the penalties, the individual mandate could no longer be considered constitutional.

A sign on an insurance store advertises Obamacare in San Ysidro, San Diego, California, U.S., October 26, 2017. REUTERS/Mike Blake

He said because the individual mandate was an “essential” part of Obamacare, the entire law, rather than just the individual mandate, was unconstitutional.

“In some ways, the question before the Court involves the intent of both the 2010 and 2017 Congresses,” he wrote. “The former enacted the ACA. The latter sawed off the last leg it stood on.”

O’Connor’s decision was issued the day before the end of a 45-day sign-up period for 2019 health coverage under the law.

About 11.8 million consumers nationwide enrolled in 2018 Obamacare exchange plans, according to the U.S. government’s Centers for Medicare and Medicaid Services.

A spokeswoman for California Attorney General Xavier Becerra, who was among a group of Democratic attorneys general defending the law, said they would appeal the decision. An appeal would go to the 5th U.S. Circuit Court of Appeals.

White House spokeswoman Sarah Sanders said in a statement the law would remain in place pending its expected appeal to the Supreme Court.

Trump hailed the ruling and called on Congress to act. “Now Congress must pass a STRONG law that provides GREAT healthcare and protects pre-existing conditions,” Trump said in a tweet.

U.S. Senate Democratic leader Chuck Schumer said he hoped the decision would be overturned.

“If this awful ruling is upheld in the higher courts, it will be a disaster for tens of millions of American families, especially for people with pre-existing conditions,” Schumer said in a statement.

In June, the Justice Department partially sided with the Republican state attorneys general, agreeing that the individual mandate must be struck down as unconstitutional but arguing several other provisions could survive.