Ban and Iraqi Prime Minister Nuri al-Maliki were giving a news conference at the time. Ban ducked, but both men were unharmed after the explosion, apparently caused by a rocket that landed nearby. After a brief pause, both men continued to take questions.
Ban said he had a "very good meeting" with al-Maliki and pledged UN support for his government.
The trip was Ban's first visit to the Iraqi capital.
It was also the first by the top UN official since his predecessor, Kofi Annan, visited in November 2005.
The United Nations scaled down its operations in Iraq after an attack on their Baghdad headquarters in August 2003 that killed the UN envoy to Iraq, Sergio Vieira de Mello, and 21 others.
(Sky, AP, AFP, Reuters)