Five handcuffed defendants tried to escape as they were escorted by two guards at the Moscow Regional Court, according to Russia’s Investigative Committee, the country’s chief investigative body.
One of the defendants tried to strangle one of the guards, and the defendants managed to escape and seized the guards’ weapons, it said in a statement.
A shootout with the court’s guards ensued, and three of the defendants were killed while the two others were wounded.
The state-owned news agency RIA Novosti quoted a lawyer, Sofya Rubasskaya, who said she heard at least 20 shots.
Three guards were injured and taken to hospital, the agency said.
The prosecutor’s office for the Moscow region said it was looking into the incident to see if the guards had violated the procedure for escorting defendants.
The shooting took place before a hearing for a gang of nine people accused of terrorising Moscow roads and killing more than a dozen motorists.
She said the building had been evacuated.
Russia media dubbed the accused “the Grand Theft Auto gang.”
Prosecutors said the gang members were placing spikes on roads, forcing the motorists out of their vehicles and shooting them dead.
The nine men, all from central Asia, are charged with 17 murders and two attempted murders.
Earlier reports from Russian news agencies said four had been killed in the gunfight.