A Virginia judge ruled against TMZ on Wednesday, allowing its former employee to testify in Johnny Depp’s bombshell defamation case against Amber Heard.

Judge Penney Azcarate — during a lunch break in the Fairfax trial — struck down the gossip site’s emergency motion seeking to prevent former field assignment manager Morgan Tremaine from being called as a rebuttal witness by Depp.

TMZ had argued that Tremaine shouldn’t be forced to give up information about a source who provided him with a video showing Depp yelling at Heard and slamming cabinet doors, which ran on the site in 2016, court papers showed.

“We are seeking to intervene to protect the relationship and their sources,” TMZ lawyer Charles Tobin told the judge.

Heard’s lawyer Elaine Bredehoft also opposed Tremaine’s testimony, claiming he should have been identified as a witness earlier in the case.

Morgan Tremaine, a former field assignment manager with TMZ, takes the stand for testimony. REUTERS

TMZ had argued that Tremaine shouldn’t be forced to give up information about a source who provided him with a video showing Depp yelling at Heard. Instagram / Morgan Tremaine

But Depp’s lawyer Ben Chew noted that Tremaine wasn’t subpoenaed but rather would be testifying of his own free will.

“In this case, it appears that the witness is willing to state the name of the confidential source without being compelled,” Azcarate said.

Follow The Post’s live coverage of the Johnny Depp-Amber Heard defamation trial

“Whether that breached a nondisclosure agreement with Mr. Tremaine and [TMZ’s parent company] EHM is not germane to this matter and can be litigated in a separate matter if EHM so chooses.”

The trial — which is in its sixth week — is expected to conclude testimony by Thursday. Jury deliberations could begin as early as Friday — after closing arguments.

The 58-year-old “Pirates of the Caribbean” star sued Heard, his ex-wife, for $50 million, alleging that she defamed him in a 2018 Washington Post op-ed in which she wrote, “I became a public figure representing domestic abuse.”

Heard countersued for $100 million, claiming that Depp defamed her when he said she lied about the abuse allegations. EPA/EVELYN HOCKSTEIN / POOL

Depp’s lawyer Ben Chew noted that Tremaine wasn’t subpoenaed but rather would be testifying of his own free will. EPA/EVELYN HOCKSTEIN / POOL

The 36-year-old “Aquaman” actress then countersued for $100 million, claiming that Depp defamed her when he said she lied about the abuse allegations.

Reps for Depp and Heard declined to comment.