Suspect Claudio Giardiello has been arrested in Milan, Italy, after he shot dead three people at the Palace of Justice.
A fourth person was found dead at the court, from an apparent heart attack.
Claudio Giardiello was reportedly a defendant in a bankruptcy case. He was arrested in a Milan suburb after fleeing the scene on a motorbike.
The dead are said to include his former lawyer and a bankruptcy court judge. The shooting has prompted scrutiny of security procedures at the courthouse.
Questions are being asked about how Claudio Giardiello managed to smuggle a weapon into a well-guarded building, use it several times and escape.
He was arrested by carabinieri officers in Vimercate, about 15 miles north-east of central Milan, near the town of Monza.
Interior Minister Angelino Alfano said the “presumed assassin” was now being held at a military police barracks in the Milan area.
Citing officials and witnesses, the newspaper La Repubblica reported that Claudio Giardiello had been attending a bankruptcy hearing when a fight broke out inside the third floor courtroom.
Claudio Giardiello pulled out a weapon and shot the lawyer, named as Lorenzo Alberto Claris Appiani, as well as another man, who is said to have been a co-defendant in the case.
According to La Repubblica, Lorenzo Alberto Claris Appiani was a former lawyer for Claudio Giardiello who was acting as a witness in the case.
The gunman then left the courtroom and headed to the office of appeals court judge, Fernando Ciampi, shooting him dead.
It is not known if Claudio Giardiello had any links to the judge.
Another two people were wounded and are being treated at a hospital.
After hiding inside the Palace of Justice for more than an hour, Claudio Giardiello fled on a motorbike, according to La Repubblica.
Claudio Giardiello was described as “aggressive” and “a little paranoid” by his former lawyer, Valerio Maraniello, in comments quoted by AFP news agency.
Visitors to the Palace of Justice have to pass through metal detectors.
Lawyers and courthouse employees with official identification are, however, regularly waved through, according to the Associated Press.
ANSA reported that one of the metal detectors was broken on April 8.
Italian PM Matteo Renzi described the attack as “a moment of great pain, of sadness”.
Matteo Renzi praised the police who arrested the gunman but said it was “unthinkable” that someone could enter a court with a weapon, and promised an inquiry into the incident.
The Palace of Justice is in the centre of Milan, only a few streets away from the city’s cathedral and main shopping district.