Police arrested the man, whom they named as Claudio Giardiello, in Vimercate, a town north of Italy’s financial center, Interior Minister Angelino Alfano tweeted. Police were holding him at a military barracks nearby, he said.
Emergency services said a fourth person was found dead in the court buildings with no apparent sign of injury. They gave no further details.
Giardiello shot the judge, Fernando Ciampi, in his office and killed his co-defendant and the lawyer in the courtroom.
The court buildings are just half a mile (1 km) from Milan’s cathedral or Duomo, a major tourist attraction. Police vans and an ambulance were parked outside the cordoned-off court buildings and the street was closed to traffic.
Security measures across Italy have been tightened following the Charlie Hebdo attacks in Paris in January and it was not immediately clear how the assailant was able to carry a gun past metal detectors and into the court buildings.
The incident raises questions about security at the city’s public venues less than a month before the Milan Expo opens on May 1, the first time the city has held the world trade fair for more than a hundred years.
“I heard a series of shots, I threw myself in the first office I could find and I thought I was going to have a panic attack,” Massimilano Monti, who works for a legal office inside the court, said.
“I have been coming here for 20 years, it’s the first time something like this has happened.”