After Ms Daniels's lawyer released a sketch of a man who allegedly told her to remain silent in 2011, Mr Trump, who denies having an affair with Ms Daniels, tweeted it was a "total con job" about a "nonexistent man".
James Otero in Los Angeles dismissed Daniels' lawsuit against Trump, calling his tweet "rhetorical hyperbole normally associated with politics and public discourse in the United States", according to the ruling obtained by CNN.
'The First Amendment protects this type of rhetorical statement'.
The amount Ms Daniels will have to pay Mr Trump has not yet been decided, Charles Harder, the president's lawyer, said.
The remaining case between Daniels and Trump is over whether the agreement meant to keep Daniels from talking about an affair she claims to have had with Trump is valid and enforceable.
The judge's ruling also entitles Trump to collect attorneys' fees from Daniels, but the amount that Daniels would need to pay will be determined later, Harder said.
Mr Trump responded by dismissing her claims in a tweet, saying: "A sketch years later about a non-existent man". Daniels has argued the agreement should be invalidated because Trump's then-personal lawyer and fixer, Michael Cohen, signed it, but Trump did not.More news: Red Dead Redemption 2 Is 60 Hours Long
More news: Saudi Arabia rejects 'threats' after Trump comments on missing journalist
More news: The Best Dressed Guests at Princess Eugenie's Royal Wedding
"Trump's contrary claims are as deceptive as his claims about the inauguration attendance", he jabbed.
"We will appeal the dismissal of the defamation cause of action and are confident in a reversal", he added.
Otero also wrote that Daniels "sought to publicly present herself as a political adversary" to Trump.
While Trump and Cohen want the court to toss out the litigation as moot, Daniels' lawyer wants to keep the case alive, hoping to compel Trump to answer questions under oath about what he may have known about the deal.
President Donald Trump has scored his first major legal victory against adult film actress Stormy Daniels.
With Daniels' accusation and another he lodged against Kavanaugh, Avenatti has become somewhat of a symbol of the anti-Trump resistance.
Instead the man threatened the adult film actress and her daughter, telling her to 'forget about this story, leave Mr. Trump alone'.