A man on trial for fraudulent bankruptcy has opened fire in Milan's courthouse, killing his lawyer, a co-defendant and a judge before being captured nearly 25 kilometres away as he fled on a motorbike, officials have said.

As the shots rang out in the tribunal, court employees barricaded themselves inside their offices and took cover under their desks while police hunted for the gunman, identified as Claudio Giardiello, who moved unimpeded from one floor to the next.

"There was a lot of panic at the beginning when people came running toward us saying there was a person with a pistol who had been shooting,'' said lawyer Mirko Ricetti, who said he locked himself in a first-floor court room after hearing a shot.

Employees and lawyers were eventually allowed to trickle out of the tribunal, women first, followed by the men who had their court ID cards checked.

Interior Minister Angelino Alfano said the suspect was caught by carabinieri police in Vimercate, near Monza, indicating he had traveled some 25 kilometres from the scene before being captured. An ambulance with escort was seen leaving the Vimercate police station, but it was not immediately clear if the gunman was inside.

Prosecutor Edmondo Bruti Liberati said the gunman first fired on his lawyer and co-defendant, killing both and seriously injuring a second co-defendant.

Afterwards, he "walked through the building, going down a floor, and killed the judge, Bruti Liberati told The Associated Press news agency.

He said it was not clear whether there was any relationship between the gunman and the judge.

He identified the slain judge as Fernando Ciampi, who worked in the civil section of bankruptcy court.

Bruti Liberati said the gunman was on trial with two others for fraudulent bankruptcy.

Giardiello's former attorney, Valerio Maraniello, told RAI state TV the case concerned a failed real estate business and that Giardiello was "very unusual" and "over the top" in his legal dealings.

Questions over security lapse

The shooting immediately raised questions about how the man gained entrance to the courthouse with a weapon, given that visitors must pass through metal detectors.

The courthouse has metal detectors at the four main entrances, but lawyers and courthouse employees with official IDs are regularly waved through without the additional security screen and accredited employees can drive into the internal garage.

Attornies Mirko and Davide Pupo noted that the metal detector from the lawyers' entrance had been removed several months ago.

Employees who emerged after the shooting suggested that the assailant could easily have gained entrance without passing through the metal detector by entering with his lawyer, though other attorneys said their clients routinely are told to go in via the public entrance.

The deputy interior minister, Filippo Bubbico, said an investigation would determine who was to blame for any security lapse, given also that the gunman was not stopped as he moved from one floor to the next to continue the spree, and then was able to flee unimpeded.

"There's no doubt that this episode signals a non-functioning of the protection mechanisms, which must be employed daily and which have worked for years at the Milan tribunal,'' he told Sky TG24.

Security concerns are particularly high in Milan given the May 1 opening of the Expo world's fair. The interior minister, Alfano, was in Milan on Thursday to preside over a public security coordination meeting for

Expo when the shooting erupted.