U.S. District Judge James Otero ruled that the case, seeking to invalidate the $130,000 agreement that kept Daniels from speaking publicly about the alleged affair, should be sent back to the California Superior Court, stating it "lacks subject matter jurisdiction."
In his ruling, Otero said that the suit was irrelevant after Trump and his former attorney Michael Cohen agreed not to enforce the nondisclosure agreement.
Daniels, born Stephanie Clifford, filed the lawsuit to rescind the NDA in March 2018 in order to allow her to discuss the alleged affair without fear of financial penalties.
"More than a year ago when I was being threatened with a $20 million lawsuit, I asked a judge to toss out this illegal NDA. Glad I stood my ground and kept fighting," Daniels wrote on Twitter after the ruling was made public.
Daniels' attorney, Michael Avenatti, declared the ruling a win for Daniels.
"The Court specifically found that Stormy received everything she asked for in the lawsuit," he wrote on Twitter.
Otero had previously dismissed a defamation lawsuit Daniels filed against Trump alleging an April 18 tweet by Trump suggested that she fabricated a composite sketch of a man who allegedly threatened her and resulted in her being exposed to ridicule and violent threats, by calling the sketch a "total con job."