Russia's Investigative Committee said the attempted getaway started while the five handcuffed men were being escorted by two guards in an elevator at the Moscow Regional Court where they were standing trial.
The defendants are accused of being members of a group, dubbed in Russian media the Grand Theft Auto Gang after the computer game.
The suspects were killed when trying to escape.
A legal counselor who was at the building when the episode happened said that no less than 20 shots were heard.
At least two other people, including a man, 45, and a woman, 40, within the courtroom were injured and hospitalized, the Moscow region health ministry said.
A lawyer for the defendants, citing the chief investigator in their case, said earlier that four of the accused had been killed in a gunfight which broke out in the building of the Moscow Regional Court. On my way from the fourth to the third floor I saw a woman sitting on a bench.
After the shootout, everyone was evacuated from the court and all hearings were postponed, the lawyer said.
Authorities said the incident took place before a hearing for the gang of nine, who are accused of the murders of 17 vehicle drivers between 2012 and 2014.
A total of nine defendants, all from Central Asia, are on trial.
In the dead of night, the gang members placed metal spikes on roads to burst the tyres of passing cars, then ruthlessly gunned down their drivers and disappeared.