MOSUL, Iraq — Some American troops could stay in Iraq for years, well beyond the scheduled withdrawal of all United States forces at the end of 2011, Defense Secretary Robert M. Gates said Friday.

In remarks to American soldiers in Mosul, north of Baghdad, Mr. Gates said that the United States and Iraq would have to negotiate the terms of any American presence in the country beyond this year. But he held out the possibility that it could happen, or at least that he had been thinking of several situations that might keep American forces in Iraq, perhaps indefinitely.

“That would be part of any negotiation, whether it be for a finite period of time, whether it would be negotiated that there be a further ramp-down over a period of two or three years, or whether we would have a continuing advise-and-assist role as we have in a number of countries,” Mr. Gates said.

A debate continues in Washington and Baghdad about where the American and Iraqi relationship will head after eight years of war. Some in the diplomatic and military ranks of both countries argue that the troops should stay.