Later Mr. Bush pledged continued security efforts in Afghanistan during a meeting in Kabul with Afghan President Hamid Karzai. Mr. Bush told Mr. Karzai that he could count on the new U.S. administration to keep fighting Afghanistan's Taliban insurgency. U.S. President-elect Barack Obama has pledged to increase troop levels in Afghanistan after he takes office in January.
After the meeting, Mr. Karzai awarded the U.S. president the Ghazi Amir Amanullah Khan Insignia for his efforts to rebuild Afghanistan and fight the country's illegal drug trade.
Once again, he traveled to Iraq in secrecy. But there were signs of change during this trip, his fourth visit since the U.S.-led invasion in March 2003.
For the first time, Mr. Bush ventured to civilian areas outside the heavily fortified Green Zone while in Baghdad. There was also a formal welcoming ceremony.
Aides said the president wanted to meet with Iraqi leaders, thank American troops and diplomats, and celebrate the completion of new security agreements with the Iraqi government.
At the conclusion of his talks with Prime Minister Nouri al-Maliki, Mr. Bush hailed the progress that has been made. But he acknowledged that the war is far from over.
"There is still more work to be done," said President Bush. "The war is not over. But with the conclusion of these agreements and the courage of the Iraqi people and Iraqi troops and American troops and civilian personnel, it is decisively on its way to being won."
But within seconds, there was a reminder of how controversial the war remains in Iraq. An Iraqi journalist threw his shoes - first one, than the other - at President Bush.
Showing the soles of ones shoes is considered an insult in Arab culture, and the man yelled out at Mr. Bush as he hurled them into the air. He was quickly led from the room, and other Iraqi reporters apologized.
President Bush shrugged off the incident and said he never felt threatened.
"These journalists here were very apologetic," said Mr. Bush. "They said this doesn't represent the Iraqi people. But this is what happens in free societies where people try to draw attention to themselves."
After his formal meetings with Iraqi officials, the president left the Green Zone by helicopter, and went to Camp Liberty - a U.S. military facility near the Baghdad airport.
He was greeted by hundreds of American troops. Mr. Bush returned the welcome with praise for their efforts to secure Iraq.
Iraq is likely to be the focal point of the Bush legacy. And the president's trip, in part, was a chance to put the best possible face on the situation there as he prepares to leave office.
About 150,000 U.S. troops and support personnel are deployed throughout the country. More than 4,200 have died since American forces moved in to oust Iraqi leader Saddam Hussein in March 2003.
The new Status of Forces Agreement celebrated during the president's visit calls for all American troops to withdraw by the end of 2011. Mr. Bush said it leaves a strong foundation for his successor, Barack Obama, who campaigned on a promise to bring the war to an end.
Some information for this report was provided by AFP, AP and Reuters.