The Federal Court found that Alphabet Inc's Google, which owns content-sharing website YouTube, earned thousands of dollars by hosting two videos attacking John Barilaro.
Barilaro was deputy premier of New South Wales until October last year.
The videos about him by commentator Jordan Shanks were viewed nearly 800,000 times between them since being posted in late 2020.
In them, Shanks questioned Barilaro's integrity, labelling him "corrupt" without evidence, and calling him racist names that were "nothing less than hate speech", the judge, Steve Rares, told the court.
The videos were a: "relentless, racist, vilificatory, abusive and defamatory campaign", and Barilaro "was traumatised by Google's and Mr Shanks' campaign and ... it caused him to leave public office prematurely", Rares said.
"I found Google's conduct in this proceeding to be improper and unjustifiable."
A Google spokesperson was not immediately available for comment.
A spokesperson for Shanks, who was a co-defendant with Google until he and Barilaro reached a settlement last year, was not immediately available for comment.