A federal judge tossed a lawsuit by porn star Stormy Daniels, which sought to invalidate a non-disclosure agreement intended to stop her from talking about her alleged affair with President Donald Trump.

Daniels has repeatedly spoken about the alleged affair, and wanted the deal declared invalid so she could talk without fear of financial penalties.

Trump's lawyers said they would not sue her for breaking it, so Daniels and her lawyer Michael Avenatti declared victory over the case.

Avenatti also took a victory lap, saying that it already resulted in Trump lawyer Michael Cohen's prison sentence for campaign finance violations over the NDAs.

A federal judge tossed out a lawsuit filed by porn star Stormy Daniel against President Donald Trump over a non-disclosure agreement (NDA) designed to keep her from speaking about their alleged affair.

The $130,000 NDA was designed to keep her from discussing her allegations that she and Trump had an affair in 2006. Trump has repeatedly denied the affair.

Trump's lawyers maintained during the lawsuit that the deal was invalid and that they will not sue her for breaking it, leading Daniels to declare victory even fter the judge tossed the lawsuit.

Daniels has spoken about her claims, including in her book, "Full Disclosure," and on "Jimmy Kimmel Live" last year. But she wanted a court to rule that the agreement was illegal, so she could speak without fear of incurring a financial penalty if the violated it.

Michael Cohen and Donald Trump. Jonathan Ernst/Reuters

Daniels argued that the deal was invalid because only Trump's then-lawyer, Michael Cohen, signed it, and Trump did not.

On Thursday James Otero, a district judge in California, said that the NDA "lacked subject matter jurisdiction" and the case should be sent back to Los Angeles Superior Court, where the case was first filed, CNN reported.

Read more: Fox News reportedly killed its story on Trump's alleged affair with Stormy Daniels weeks before the election

The Associated Press reported that Otero said that his decision does not mean that litigation would continue at the Los Angeles court, but that Daniels may be entitled to legal fees.

Daniels takes a victory lap even as her case is thrown out

Daniels and her lawyer, Michael Avenatti, claimed victory on Thursday despite Otero's decision to throw out the lawsuit, because Trump's lawyers said they would not seek penalties from her for breaking the deal.

Daniels tweeted on Thursday: "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 & kept fighting."

She was referring to Trump's attorney's seeking $20 million in damages from Daniels in 2018, claiming that she violated a NDA. That lawsuit was dropped in September 2018.

Avenatti also tweeted that Daniels had "won," saying that "we forced Trump and Cohen to cave and Cohen has been convicted."

Daniels, accompanied by her attorney, Michael Avenatti, talks to the media as she leaves federal court in New York in April 2018. AP Photo/Mary Altaffer

Cohen, as Trump's lawyer and fixer, arranged the NDA and facilitated the $130,000 payment to Daniels.

He told a federal court in August 2018 that he made an illegal campaign finance contribution on October 27, 2016 — the day a $130,000 payment to adult-film star Stormy Daniels was finalized — and said he did so at the behest of Trump.

Read more: Michael Cohen pleads guilty and says he broke campaign finance law at Trump's direction

Cohen has been sentenced to three years in prison after pleading guilty to nine charges, including campaign finance violations related to payments to women, including Daniels, who claimed to have affairs with Trump.

Otero also dismissed a separate defamation lawsuit that Daniels brought against Trump last year, ordering her to pay Trump $293,000 in legal fees.