Justin Baldoni will write his first check in the wake of his legal war with Blake Lively ... because his production company was just ordered to pay The New York Times legal fees after his failed lawsuit.
According to legal documents obtained by TMZ ... Baldoni's Wayfarer Studios has been ordered to cough up $171,616 to The Times ... after a judge tossed his suit against the newspaper and another against Blake last summer.
As you know ... Justin and Wayfarer were suing Blake and Ryan Reynolds for $400 million and The Times for $250 Million, alleging defamation over an article about all the drama on the "It Ends With Us" movie set ... a story Baldoni alleged was a part of a smear campaign against him.
The Times then sued him back under New York's anti-SLAPP law ... seeking "compensatory and punitive damages against plaintiffs who, like Wayfarer, commence or continue meritless legal claims for the purpose of 'harassing, intimidating, punishing or otherwise maliciously inhibiting the free exercise of speech."
A source close to Wayfarer tells TMZ ... "The team fully understood the enormous risks involved in taking on The New York Times over what were now proven blatant falsehoods published by journalist Megan Twohey.
The source added ... "The case was lost on journalistic privilege, not on the facts. Very few people have successfully challenged The New York Times in modern history, but pursuing the case was one of the only ways to bring the evidence into the public record, challenge the hideously, false narrative being advanced by Blake Lively and expose the serious inconsistencies at the heart of her claims. For the Wayfarer team, getting that evidence into the open was a significant victory in itself. It also shows how completely out of reality Lively\u2019s attempt to extort millions out of Wayfarer for attorney fees for just one portion of their defamation countersuit really is."
As we reported ... a federal judge ruled that Baldoni and Wayfarer must pay Blake's legal fees ... but the final amount is currently being hashed out in court. Blake is asking for a little more than $8 million.