The man, believed to be a defendant in a bankruptcy case, had fled the scene on a scooter but was captured by police in Vimercate, a city some 25 kilometres outside Milan, Alfano said on Twitter.
Catturato a Vimercate il presunto assassino di Milano. Ora si trova in caserma dei Carabinieri.— Angelino Alfano (@angealfa) April 9, 2015
The sound of shots sparked panic on Thursday morning, with lawyers fleeing the scene while police officers searched for the gunman, prosecutor Giovanni Canzio said.
The dead were named by the Italian media as judge Fernando Ciampi and lawyer Lorenzo Alberto Claris Appiani, both shot on the third floor of the building after Giardiello managed to get a gun past security.
A third person was found dead inside the building after apparently suffering a heart attack, possibly brought on by the shooting, emergency services said.
Two people were injured in the shootout and one is in a serious condition.
"All of a sudden we heard at least three or four shots," lawyer Marcello Ilia told AFP outside the court.
"We tried to find out what was going on. There were suddenly lots of police officers who told us not to leave the room, they shut us in," he said.
"After a few minutes we came out. They told us someone in a suit and tie was armed and at large in the court," he said.
The Palace of Justice is in the historic centre in Milan, only a few streets away from the city's cathedral and shopping district.
Judge Gherardo Colombo told journalists outside the court that he was "dazed and shocked" by the shootout.
"I knew Judge Ciampi personally, it's absurd that one can die like that, while you're doing your job," he said, suggesting "an anti-judiciary climate" may be to blame.
Nearby the courtroom, a shop worker told The Local there was lots of confusion but shops remained open.
"There's a lot of confusion, people stood outside the court, but we haven't been told to close the shop."
Regional authorities were shocked that anyone had managed to get into the court building with a gun.
"It's disturbing that just anyone can get into the Palace of Justice armed," said the head of the Lombardy region, Roberto Maroni.
"The fact that we're not talking about an organisation which surveyed the place first makes it even more perturbing," he said.
Meanwhile, Elvio Crispino, a Milan-based lawyer, told The Local he is struggling to understand how someone managed to enter the building with a gun as security is so tight.
"Security is high. They do checks and there's a metal detector," he said.
Alfano, who was in Milan for a national committee meeting on public order and safety ahead of the 2015 Milan expo which opens in May, was called on to investigate security at the court.
Who is Claudio Giardiello?
La Repubblica reported that Giardiello is a 57-year-old businessman from Beneveneto, a town in Campania, but lives in the Lombardy province of Brianza.
He worked in construction and owned several companies, the newspaper said, but had fallen on hard times, which resulted in legal wrangling.
Valerio Maraniello, who once acted as a lawyer for the shooter, told AFP his ex-client was "an aggressive person, a little paranoid."
"He was always convinced people were trying to cheat him. He never listened to advice," he said, adding that he was "not completely surprised" by the deadly attack.