BAGHDAD, Iraq (CNN) -- A man identified as an Iraqi journalist threw shoes at -- but missed -- President Bush during a news conference Sunday evening in Baghdad, where Bush was making a farewell visit.
Bush ducked, and the shoes, flung one at a time, sailed past his head during the news conference with Prime Minister Nuri al-Maliki in his palace in the heavily fortified Green Zone.
The shoe-thrower -- identified as Muntadhar al-Zaidi, an Iraqi journalist with Egypt-based al-Baghdadia television network -- could be heard yelling in Arabic: "This is a farewell ... you dog!"
While pinned on the ground by security personnel, he screamed: "You killed the Iraqis!"
Al-Zaidi was dragged away. While al-Zaidi was still screaming in another room, Bush said: "That was a size 10 shoe he threw at me, you may want to know." Watch Bush duck the shoes »
Hurling shoes at someone, or sitting so that the bottom of a shoe faces another person, is considered an insult among Muslims.
Al-Baghdadia issued a statement Sunday demanding al-Zaidi's release.
Al-Zaidi remained in custody Monday while the Iraqi judiciary decides whether he will face charges of assaulting al-Maliki, a government official said.
The official said al-Zaidi is being tested for alcohol and drugs to determine if he was fully conscious during the incident.
Al-Zaidi drew international attention in November 2007 when he was kidnapped while on his way to work in central Baghdad. He was released three days later.
Bush had been lauding the conclusion of a security pact with Iraq as journalists looked on.
Iraq gives final OK to U.S. pullout plan
Blackwater prosecutors meet with Iraqis
Ex-Blackwater guards charged with manslaughter
"So what if the guy threw his shoe at me?" Bush told a reporter in response to a question about the incident.
"Let me talk about the guy throwing his shoe. It's one way to gain attention. It's like going to a political rally and having people yell at you. It's like driving down the street and having people not gesturing with all five fingers. ...
"These journalists here were very apologetic. They ... said this doesn't represent the Iraqi people, but that's what happens in free societies where people try to draw attention to themselves."
Bush then directed his comments to the security pact, which he and al-Maliki were preparing to sign, hailing it as "a major achievement" but cautioning that "there is more work to be done."
"All this basically says is we made good progress, and we will continue to work together to achieve peace," Bush said.
Bush's trip was to celebrate the conclusion of the security pact, called the Strategic Framework Agreement and the Status of Forces Agreement, the White House said.
The pact will replace a U.N. mandate for the U.S. presence in Iraq that expires at the end of this year. The agreement, reached after months of negotiations, sets June 30, 2009, as the deadline for U.S. combat troops to withdraw from all Iraqi cities and towns. The date for all U.S. troops to leave Iraq is December 31, 2011.
Bush called the passage of the pact "a way forward to help the Iraqi people realize the blessings of a free society."
Bush said the work "hasn't been easy, but it has been necessary for American security, Iraqi hope and world peace."
Bush landed at Baghdad International Airport on Sunday and traveled by helicopter to meet with President Jalal Talabani and his two vice presidents at Talabani's palace outside the Green Zone.
It marked the first time he has been outside the heavily fortified Green Zone in Baghdad without being on a military base.
The visit was Bush's fourth since the U.S.-led invasion of Iraq in March 2003.
Afterward, Talabani praised his U.S. counterpart as a "great friend for the Iraqi people" and the man "who helped us to liberate our country and to reach this day, which we have democracy, human rights, and prosperity gradually in our country."
Talabani said he and Bush, who is slated to leave office next month, had spoken "very frankly and friendly" and expressed the hope that the two would remain friends even "back in Texas."
For his part, Bush said he had come to admire Talabani and his vice presidents "for their courage and for their determination to succeed."
As the U.S. and Iraqi national anthems played and Iraqi troops looked on, he and the Iraqi president walked along a red carpet. Watch President Bush and Iraq's president walk the red carpet »
Bush left Iraq on Sunday night and arrived Monday morning in Afghanistan, where he will met with President Hamid Karzai and speak with U.S. troops.
In remarks to reporters, National Security Adviser Stephen Hadley, who traveled with Bush, described the situation in Iraq as "in a transition."
"For the first time in Iraq's history and really the first time in the region, you have Sunni, Shia and Kurds working together in a democratic framework to chart a way forward for their country," he said.
On Monday, new violence in Iraq showed that work remains to be done.
A suicide car bomb attack killed at least three people and wounded 31 others west of Baghdad on Monday, an Iraqi Interior Ministry official said. The noontime bombing targeted civilians on a road between Khan Dhari and Abu Ghraib, according to the official.
Also, the U.S. military said three militants were killed and 13 others were detained in operations targeting al Qaeda in Iraq on Sunday and Monday. The incidents took place in Baiji, Tall Sumayyir, Tikrit, near the towns of Abu Ghraib, Mahmoudiya and Kirkuk.