London: NATO will withdraw its Iraq training mission at year-end after Baghdad refused to grant it legal immunity, Iraq's top security adviser said on Sunday, mirroring the nearly-complete pullout of US forces.

The decision, which "surprised" Iraq, means NATO's troops will depart in the coming weeks for the same reason an agreement for a post-2011 US training mission fell through, despite NATO having agreed in principle to staying through to the end of 2013.

"NATO surprised us with this decision," National Security Adviser Falah al-Fayadh said in an interview aboard a flight transporting Prime Minister Nuri al-Maliki to Washington.

"We are sorry that NATO has advised that it will withdraw its mission from Iraq... because immunity is something that is out of the government's reach," he added, saying Baghdad was informed of the decision on Thursday.

Fayadh added: "I would have preferred that there would be cooperation with NATO in other aspects, and not only through its mission in Iraq, and I was hoping that this mission would stay."

On November 29, Iraqi government spokesman Ali al-Dabbagh said Iraq was studying a contract to extend NATO's presence in Iraq beyond year-end, but noted that such a deal would not grant its troops immunity from prosecution.

And on the same day, a NATO spokesman said the grouping had been asked by Maliki to "extend its training mission until the end of 2013."

"The North Atlantic Council (the ambassadors of the 28 NATO Allies) has accepted this request in principle. Technical details are currently being worked out," the spokesman said at the time.

Major General Jeffrey Buchanan, the spokesman for US forces in Iraq, said that Baghdad and NATO were working on an agreement that would see around 150 trainers beyond year-end.

NATO's training mission in Iraq was aimed at assisting "in the development of Iraqi security forces training structures and institutions", and as of November 2011, 12 countries were represented in its force.

The failure to agree on immunity from prosecution closely mirrors Iraq's refusal to grant US soldiers similar protections earlier this year, sinking a potential deal between the two countries that means all American soldiers left in Iraq will leave by year-end.

Around 6,000 US troops remain stationed in the country on four bases, down from peaks of nearly 170,000 soldiers and 505 bases.