Four people have been shot dead after a shooting broke out at the Palace of Justice in the centre of Milan.

A man on trial for fraudulent bankruptcy opened fire in the courthouse, killing his lawyer, a co-defendant and a judge, officials said. He has been identified in Italian media as Claudio Giardiello.

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", Mr Bruti Liberati told the Associated Press.

The judge, named in Italian media as Fernando Ciampi, was reportedly shot in his office. The fourth person may have died from a heart attack, the BBC reports.

In pictures: Milan courthouse shooting Show all 12 1 /12 In pictures: Milan courthouse shooting In pictures: Milan courthouse shooting Italy Rescuers and police help an injured man outside the tribunal building in Milan In pictures: Milan courthouse shooting Italy Rescuers and police help an injuried out of the Justice Palace in Milan In pictures: Milan courthouse shooting Italy A plainclothes policeman helps to evacuate people from the tribunal building in Milan, after a shooting was reported inside a courtroom In pictures: Milan courthouse shooting Italy Police officers run at the entrance to Milan's court during the shooting In pictures: Milan courthouse shooting Italy Policemen run out of the tribunal building in Milan In pictures: Milan courthouse shooting Italy Rescuers and police help an injuried out of the Justice Palace in Milan In pictures: Milan courthouse shooting Italy A plainclothes policeman helps to evacuate people from the tribunal building In pictures: Milan courthouse shooting Italy A police sniper stands in front of a secondary entrance of the tribunal of Milan In pictures: Milan courthouse shooting Italy People are evacuated from the tribunal of Milan In pictures: Milan courthouse shooting Italy Police cars surround the tribunal of Milan In pictures: Milan courthouse shooting Italy Police snipers arrive at the tribunal of Milan In pictures: Milan courthouse shooting Italy People leave the tribunal of Milan after a man opened fire inside a court

Witnesses told AFP the gunman was in a suit and tie and fired "at least three or four shots".

Italy's interior minister Angelino Alfano said the shooter was detained 25 kilometres away from the building after fleeing on a motorbike.

Witnesses reported barricading themselves inside their offices and taking cover under their desks as police searched for the shooter. Court staff left the building, women first, followed by the men who had their court ID cards checked by authorities.

"There was a lot of panic at the beginning when people came running towards us saying there was a person with a pistol who had been shooting," said lawyer Mirko Ricetti, who locked himself in a first-floor courtroom after the shooting began.

The shooting has raised questions over how the gunman managed to get a weapon past metal detectors in the court house.