The U.S. military, meanwhile, reported a major breakthrough in the campaign against rogue Shiite militants, saying it captured two brothers responsible for a sophisticated sneak attack that killed five American soldiers in January.
The Katyusha rocket that hit near Secretary-General Ban Ki-moon was fired from a mainly Shiite area on the east bank of the Tigris River, not far from The Associated Press office. The heavily guarded Green Zone on the opposite bank is home to the U.S. Embassy, Iraq's government and the parliament.
Ban's unannounced stop in the Iraqi capital was the first visit by a U.N. secretary-general since Kofi Annan, his predecessor, came to Baghdad in November 2005. The U.N. Security Council issued a statement strongly condemning the rocket firing as an "abhorrent terrorist attack."
The U.N. presence in Iraq has been much smaller than planned since militants bombed the organization's Baghdad headquarters on Aug. 19, 2003, and killed 22 people, including the top U.N. envoy, Sergio Vieira de Mello.
That was one of the first major attacks as Sunni Arab insurgents began rallying against American forces and other foreign troops after the U.S.-led invasion. Foreign U.N. staff withdrew from Iraq in October 2003 after a second assault on its offices and other attacks on humanitarian workers. A small staff has gradually been allowed to return since August 2004.
Iraq's Shiite-dominated government has been quietly pushing for a greater U.N. role and was banking on decreased violence in the capital to show that it was returning to normal six weeks into a joint security crackdown with American forces.
"We consider it a positive message to (the) world in which you confirm that Baghdad has returned to playing host to important world figures because it has made huge strides on the road toward stability," Prime Minister Nouri al-Maliki told Ban moments before the rocket attack.
Ban's presence was broadcast after he arrived, but the trip had been kept so secret even his press spokeswoman didn't know he was in Iraq. His public schedule had called for Ban to leave New York on Thursday for a trip to Egypt, Israel and an African Union summit in Saudi Arabia.
The U.S. military announced three Americans died in combat Wednesday - an Army soldier slain in Baghdad and another soldier and a Marine killed in Anbar province. At least 44 Iraqis were killed or found dead Thursday, including 25 bodies dumped in the capital, all showing signs of torture, police said.
In the campaign against Shiite extremists, the U.S. military said it captured two brothers who were "directly connected" to the Jan. 20 sneak attack that killed five American soldiers guarding the provincial headquarters in Karbala, a city 50 miles south of Baghdad.
Qais al-Khazaali, his brother Laith al-Khazaali and several other members of their network were rounded up over the past three days, the military said.
Gunmen speaking English, wearing U.S. military uniforms and carrying American weapons killed one American soldier during that attack, then carried off four captured soldiers and later shot them to death about 25 miles from Karbala.
An initial statement by the U.S. military on the day of the raid said five soldiers were killed while "repelling" the attack on the compound in Karbala. But after a Jan. 26 report by The Associated Press, the military reversed itself and confirmed that four of the guards had been abducted before being slain in a neighboring province. The brazen assault was conducted by nine to 12 gunmen posing as an American security team, the military confirmed. The attackers traveled in black GMC Suburbans - the type of SUV used by U.S. government convoys. The arrest announcement came a day after the AP reported that two senior commanders from the Mahdi Army militia had identified one of the brothers, Qais al-Khazaali, as leader of up to 3,000 fighters who defected from the group. They said the defectors were now financed directly by Iran and no longer loyal to the militia's leader, firebrand cleric Muqtada al-Sadr. Qais Al-Khazaali, a Shiite cleric in his early 30s, was a close al-Sadr aide in 2003 and 2004. He was al-Sadr's chief spokesman for most of 2004 but had not been seen in public since late that year. The U.S. military also said it released another al-Sadr aide, Ahmed al-Shibani, at the request of Iraq's prime minister. The military said al-Shibani could help with the U.S.-Iraqi drive to quell violence in Baghdad, "moderate extremism and foster reconciliation." Al-Shibani was captured in the Shiite holy city of Najaf during fierce clashes in 2004 between U.S. forces and al-Sadr's militia, which has largely cooperated with the new security push in Baghdad. Iraq's government released a photograph showing al-Maliki meeting with a smiling al-Shibani, underlining the close ties between the Shiite prime minister and al-Sadr. Al-Maliki won his post last year with the support of al-Sadr, whose loyalists hold 30 of parliament's 275 seats. Also Thursday, the Iraqi government said it had been in indirect talks with some Sunni insurgent groups for several months but the effort to persuade the groups to lay down their arms remained deadlocked because it wouldn't set a timetable for a U.S. troop withdrawal. More talks were planned, but Saad Yousif al-Muttalibi of the Ministry of National Dialogue and Reconciliation would give no details. He refused to identify the groups, but said they did not include al-Qaida in Iraq or Saddam Hussein loyalists.