The assault near the heavily fortified Green Zone, where several Western embassies and government offices are located, fanned fears about Iraq's still fragile security a decade after the invasion that ousted Saddam Hussein.
Three car bombs exploded and a suicide bomber blew himself up in broad daylight in the heart of the capital on Thursday.
Another suicide bomber then walked into the justice ministry and set off his device while militants attacked the building. Iraqi security forces eventually regained control.
"In a blessed raid among a series of operations for revenge ... Baghdad's knights undermined another vicious bastion which was always a tool against Sunnis, torturing, terrifying, imprisoning and executing them," al-Qaeda said in a statement published online.