In a wild outburst in a Moscow courtroom, Canadian Paul Whelan shouted down a Russian judge Tuesday as he tried to defend himself against charges of being a spy.

"I was set up. I did not commit a crime," Whelan yelled from the glassed-in prisoners box during a hearing on having his eight-month detention extended.

Whelan, who is 49 and originally from Ottawa, also has passports from the United States, the United Kingdom and Ireland. He has been held by Russian authorities since being arrested in a Moscow hotel and charged with espionage in December 2018.

In previous court appearances, he has criticized Russia's justice system and used the occasions to convey messages back to his family.

Tuesday's hearing, however, was especially chaotic. Whelan tried to drown out the judge, who was reading the detention order into the record.

"I can speak louder than you, your honour!" he yelled.

Watch as Whelan tells the court what he thinks of the case against him.

Canadian Paul Whelan proclaims his innocence and denounces Russia's legal system in a chaotic court scene. 0:42

"I have to tell you my dog, Flora, a golden retriever, has received better medical treatment than I have received from the government of Russia," he continued.

Whelan is suffering from a hernia, and his lawyer says he's often in a great deal of pain.

"I'd like to say to my family that I love them and I appreciate their support. They know this is garbage. Everyone in the West knows this is garbage."

Whelan, a former U.S. marine, was working as a security consultant for a U.S. auto parts company when he says he came to Moscow for the wedding of another ex-marine in December 2018. Previously, Whelan had been a frequent visitor to the country and had made many acquaintances online.

The exact sequence of events that led up to his arrest has never been fully disclosed, but on Tuesday he and his lawyers provided some new details.

Whelan, a former U.S. marine, looks out from a defendants' cage before a court hearing in Moscow on Aug. 23. (REUTERS)

Whelan said in court that on the morning of Dec. 28, he returned to his room in Moscow's Metropol Hotel after taking a tour of the Kremlin, which is just a few blocks away.

He said a Russian man he had known for 10 years came to his room and "put something in my pocket."

Whelan believes his so-called friend was really an officer with Russia's secret police. Russian media have reported that the item was a USB stick that contained a list of names of Russians working at a classified security agency.

"I didn't even know I had it until I was arrested," Whelan said.

Neither Whelan nor his lawyers would name the man they believe set him up.

CBC News has learned that the pair met on the internet and that the Russian man lived in Sergiev Posad, a popular tourist town on Moscow's Golden Ring, a cluster of ancient towns about an hour from Moscow.

The two men got to know each other, and Whelan became a frequent visitor. They had dinner together just three days before Whelan's arrest.

Whelan stands outdoors with his friend's dog during a visit to the town of Sergiev Posod, Russia, in January 2018. Whelan says he now believes the friend was an FSB agent. (Tatyana Makeyeva)

Outside court, Whelan's lawyer Olga Karlova said the bulk of the evidence against her client is from surveillance and wiretap recordings of conversations between him and the undercover FSB officer.

"There are some conversations, but it can be interpreted this way or that way. It depends on the situation."

"We haven't seen any strict, direct evidence of his guiltiness yet," she added.

His brother David Whelan, who lives in Newmarket, Ont., says Tuesday's outburst in court points to the stress Paul Whelan is enduring.

"I think after almost nine months he has run out of patience," he told CBC News in an interview. "It's all bogus."

Initially, after Whelan's arrest, there had been speculation that he might be quickly traded for a Russian held by Britain or the United States, but such a prisoner swap hasn't happened.

"I think there needs to be relationships between governments for those sorts of trades to happen, and there doesn't seem to be that kind of relationship between any of the governments that are representing Paul's interest."

Last week, a bipartisan group of U.S. lawmakers in the Senate and House of Representatives tried to turn up the political pressure on Russia by passing dual resolutions calling on Russia to present credible evidence of Whelan's guilt or else release him.

They were joined in Washington by Whelan's sister, Elizabeth.

Paul Whelan's sister Elizabeth, centre, appears with U.S. lawmakers including Sen. Gary Peters., Democrat from Michigan, right, speaks at a news conference on Capitol Hill in Washington, D.C., last week. (Facebook, Sen Gary Peters)

But in a tweet, Russia's Foreign Ministry dismissed the criticism that Whelan is being held unfairly, claiming he was caught "red-handed" and that complaints about their handling of the case was "disinformation."

David Whelan says the family has been preparing themselves for a bad outcome.

He says he expects a formal trial will start early in 2020 and that the only possible result will be a guilty verdict.

With their parents already in their 80s, he says they are considering a trip for them to visit Paul in Russia during the trial, on the assumption that it may be the last time the three of them will see each other.

"I think we are looking at giving a final opportunity to get together before he goes to a labour camp or detention centre."