Judge Reed O'Connor of the U.S. District Court for the Northern District of Texas, in Fort Worth, heard arguments in the case in early September, but did not issue his ruling until Friday evening.
The decision is a huge swipe at the 2010 health law and sets the stage for a bigger fight in appeals courts.
The coalition of states challenging the law was led by Texas Attorney General Ken Paxton and Wisconsin Attorney General Brad Schimel, both Republicans.
"The remainder of the ACA is non-severable from the individual mandate, meaning that the Act must be invalidated in whole", O'Connor wrote. They argued that the mandate remains constitutional and that the rest of the law, in any event, can stand without it.
"As I predicted all along, Obamacare has been struck down as an UNCONSTITUTIONAL disaster!"
President Trump celebrated the decision, calling it "Great news for America!".
The Affordable Care Act was struck down by a Texas federal judge in a ruling that casts uncertainty on insurance coverage for millions of U.S. residents.
Russian gun rights activist to admit spy charge in the US
She pleaded not guilty to both charges and has since been held in solitary confinement awaiting sentencing. The first message said the funding of her legal defense as in a "critical" state.
In June, the Justice Department declared the healthcare law's "individual mandate" unconstitutional in federal court.
Analysts said the ruling might cause chaos in the final hours of Obamacare enrollment but wouldn't have an immediate effect, since the mandate penalty doesn't shrink to zero until the new year and liberal officials will move for a stay.
US Senate Democratic leader Chuck Schumer said: "If this bad ruling is upheld in the higher courts, itwill be a disaster for tens of millions of American families".
Becerra called Friday's ruling "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".
Meanwhile, the White House called on Congress to replace Obamacare with an affordable healthcare system which protects people with pre-existing conditions. They don't need their own health insurance. California and other states had intervened to defend the 2010 health care law after the Trump administration declined to defend its provisions that guarantee coverage for people with pre-existing conditions, arguing that those provisions can not be separated from the mandate.
Seema Verma, the administrator of the Centers for Medicare and Medicaid Services, told reporters in November that the administration had contingency plans in place for a ruling if the law was overturned, but declined to elaborate on them.
Repealing the Affordable Care Act could lead to about 15 million people losing their health insurance coverage, according to Ana Gupte, a Wall Street analyst at Leerink Partners.