ABC News' Kirit Radia reports: Defense Secretary Robert Gates made a surprise trip to Iraq today during a swing through the Middle East. He is meeting with top US commanders and Iraqi leaders as American forces transition to more advisory roles throughout the country. He traveled to Baghdad after visiting a southern command post in Talil, where US forces are mainly advising their Iraqi counterparts. The arrangement was hailed as a model for future US and Iraqi military cooperation. Gates’ visit comes just after US forces pulled out of Iraqi cities in accordance with a troop agreement signed by the Bush administration late last year. He said the withdrawal from urban areas has allowed Iraqi forces to assume the lead in security. "Nobody's the boss or the occupier, or however you want to put it. But there's a real sense of empowerment by the Iraqis," Gates said. Under the troop agreement, the bulk of US forces will withdraw from Iraq by the end of 2011. June’s pullout from Iraqi cities was seen as a major test whether Iraqi troops could take on the task of sustaining Iraq’s fragile peace. Gates said that so far he has seen positive signs, telling reporters "Less than a month into it, I'm really heartened." Still, there have been bumps in the road. An Iraqi officer recently ordered some US soldiers detained after they killed several Iraqis while pursuing insurgents last week. Iraq’s Prime Minister Nouri al-Maliki said in an interview published Sunday that the Iraqi officer’s actions were “out of line.” While the pact does restrict some US troop movements, it does not ban American forces from all military action in the country. Maliki said that the troop agreement "clearly states that American forces have the right to defend themselves, and that's what they did." Gates is also expected to visit Iraq’s Kurdish north, where disputes over territory and oil revenue have raised concerns of renewed instability. Last week Maliki visited Washington where he met with President Obama, Secretary of State Hillary Clinton, and other top US officials and lawmakers.