Police said Claudio Giardiello shot the judge, Fernando Ciampi, in his office, having earlier opened fire in a courtroom killing a lawyer and his co-defendant in a bankruptcy trial. A fourth person was wounded.
In all, Giardiello fired 13 shots inside the Palace of Justice in central Milan before fleeing, police said. They arrested him in Vimercate, a town north of Italy's financial center, Interior Minister Angelino Alfano said on his twitter feed.
Public security was tightened across Italy following January's Charlie Hebdo attacks in Paris, and it was not immediately clear how the assailant was able to carry a gun into the court buildings.
Milan chief prosecutor Edmondo Bruti Liberati told reporters the attacker likely carried a false identification badge and entered through a side entrance reserved for lawyers and court employees, where there is no metal detector.
Prime Minister Matteo Renzi said the priority was to ensure nothing similar ever happened again.