"It was the longest hour in my life," said Asmaa Abbas, who cowered alongside colleagues in her third-floor office while the assailants battled security forces outside.
There was no immediate claim of responsibility, but the attack bore the hallmarks of al-Qaida's Iraqi arm. The group, known as the Islamic State of Iraq, frequently uses car bombs, suicide bombers and coordinated blasts in an effort to undermine Iraqis' confidence in the Shiite-led government.
The attack began shortly after midday in Baghdad's Allawi area, a largely commercial district that is home to the Iraqi National Museum and the city's main bus station.
At least two blasts, including one car bomb and another believed to be from a suicide bomber, went off near the Justice Ministry.
Two other car bombs exploded nearby in what police believe was an effort to confuse the authorities. One struck near the bus station and the other hit the headquarters for a VIP protection force that provides bodyguards for lawmakers, government ministers and other senior officials.
Amid the chaos, approximately six gunmen wearing police uniforms charged inside the ministry building, according to a police officer who was among the troops sent to clear the area. A gun battle soon broke out between the intruders and security forces.
After about an hour, security forces stormed the building, and some of the gunmen detonated explosives they were wearing, the officer on the scene said.
More than 1,000 people in the building at the time of the attack, said Deputy Justice Minister Busho Ibrahim, adding that the justice minister was traveling abroad.
Ibrahim said he hid behind the locked door of his office, ordering his bodyguards to shoot anyone who tried to enter.
He described a terrifying ordeal, with at least one suicide bomber blowing himself up on the ground floor of the building, shattering windows and damaging the ceiling.
"When the explosions and shooting started, the guards evacuated me out a back door, and I have no idea what happened after that," he said, speaking over the telephone from outside the building.
The attack killed 24 people in addition to the gunmen and wounded 57 others, police said. The dead include seven police officers.
Hospital officials confirmed the casualty numbers. The officials spoke on condition of anonymity because they were not authorized to speak to the media.
Parliament speaker Osama al-Nujaifi demanded an investigation into how the raid happened.
"This blatant security violation targeting an important government building in the middle of the capital only shows the weakness of the security forces (and) their limited capabilities," he said in a statement.
Justice Ministry employees had moved to this facility after a 2009 attack on their nearby headquarters, which is now being repaired. That attack was part of a double car bombing which killed at least 147 people.
Thursday's attack took place about a mile away from the heavily fortified Green Zone, which houses several foreign embassies and Iraqi government offices.
The U.S. Embassy vowed to work with Baghdad to combat those who carry out "such atrocious and senseless crimes."
A separate attack by gunmen on a military checkpoint in the town of Latifiyah, about 30 kilometers (20 miles) south of the capital, left four soldiers dead and another wounded, two police officers and a medic said.
Violence in Iraq has subsided from its peak in 2006 and 2007, but deadly attacks remain frequent a decade after the March 20, 2003 start of the American-led invasion.
Iraq's government is being challenged by weekly protests that began in December from Sunnis angry over perceived discrimination. The demonstrations have been largely peaceful, and most Iraqi Sunnis do not support al-Qaida.
But al-Qaida hopes to exploit the increasing tensions. It believes Shiites are heretics and that Iraq's government is too closely allied with neighboring Shiite powerhouse Iran.
Earlier this week, al-Qaida claimed responsibility for the deaths of 51 Syrian soldiers and nine Iraqis in a well-planned assault in western Iraq on March 4, intensifying concerns that the terror group is coordinating with Islamist rebels fighting to topple Syrian President Bashar Assad.