Stormy Daniels’ defamation lawsuit against President Trump was tossed out Monday — with a federal judge ordering the porn star to pay the president’s legal fees, according to court records.

The case stemmed from a Trump tweet that called Daniels, who claims she had an affair with him, “a total con job.” Trump has denied the affair.

Judge S. James Otero, a US District Court judge in Los Angeles, said Monday the comments made in the president’s tweet appeared to be an opinion protected by the First Amendment.

“The tweet in question constitutes ‘rhetorical hyperbole’ normally associated with politics and public discourse in the U.S.,” the ruling reads. “The First Amendment protects this type of rhetorical statement.”

The president’s attorney Charles J. Harder called the ruling a “victory” in a statement to Fox News. The amount Daniels needs to pay will be decided at a later date, he said.

“No amount of spin or commentary by Stormy Daniels or her lawyer, Mr. Avenatti, can truthfully characterize today’s ruling in any way other than total victory for President Trump and total defeat for Stormy Daniels,” the statement said.

Daniels’ lawyer, Michael Avenatti, said he planned to appeal the dismissal.

Daniels, whose real name is Stephanie Clifford, claimed she was approached in 2011 by a man who threatened her to keep quiet about her alleged affair with Trump. Avenatti released a sketch of the supposed suspect on April 17.

The next day, the president tweeted: “A sketch about a nonexistent man. A total con job playing the Fake News Media for Fools (but they know it)!”

In the suit, Daniels, 39, claimed she received death threats and had to hire bodyguards following the tweet. By sending the tweet, “Mr. Trump used his national and international audience of millions of people to make a false factual statement to denigrate and attack Ms. Clifford,” the suit claimed.

But Monday’s ruling disagreed.

Trump made a “one-off rhetorical comment, not a sustained attack on the veracity of [Daniels’] claim,” the ruling states.

Judge Otero also agreed with Trump’s attorneys that Daniels hadn’t proven the president acted with malice when sending the tweet.

The ruling does not affect Daniels’ primary case against Trump and his former lawyer Michael Cohen, seeking to invalidate her 2016 nondisclosure agreement.