U.S. Defence Secretary Robert Gates told U.S. soldiers on Wednesday they were in the final phase of engagement in Iraq after ending combat missions, and history would judge if the invasion had been worth it.

On a visit to troops in Ramadi, scene of some of the fiercest fighting of the 7-1/2 year war, Gates said he believed they still deserved combat pay even though their mission had officially turned its focus to assisting Iraqi forces.

Combat operations have ceased, he said.

We're still going to work with the Iraqis on counter-terrorism. We're still doing a lot of training. And advising and assisting ... So I would say that we have moved into the final phase of our engagement in Iraq.

Both Gates and Vice President Joe Biden were in Iraq on Wednesday to attend a ceremony at which the U.S. military's outgoing commander in Iraq, General Raymond Odierno, will hand over to incoming commander, Lieutenant General Lloyd Austin.

The change of command comes a day after the formal end of the U.S. combat mission launched by President Barack Obama's predecessor in the White House, George W. Bush, with the 2003 invasion. Obama told Americans in an address from the Oval Office that it was time to turn the page on Iraq.

Around 50,000 U.S. soldiers will remain in Iraq up to a withdrawal by the end of 2011 agreed in a bilateral security pact between the United States and Iraq. But they will advise and assist Iraqi forces, rather than lead the fight against a stubborn Sunni Islamist insurgency and Shi'ite militia.

Security remains a big worry in Iraq where attacks against Iraqi security forces have been increasing, and there are concerns the end of U.S. combat operations will leave an even bigger gap for insurgents to exploit.

Tensions are also running high because of a stalemate in efforts to form a new government six months after an inconclusive election.

Gates said judging the invasion required a historian's perspective and depended on Iraq's political future. If it remained a democracy and played a constructive role, it could have a significant impact on the Middle East, he said.

How it all weighs in the balance over time I think remains to be seen, he said.

This is going to be a work in progress for a long time. This is a new thing in the several thousand year history of Iraq and it's a pretty new thing in this region of the world. But I think they're off to a good start.

(Writing by Serena Chaudhry; Editing by Michael Christie and Louise Ireland)