"I worry that the great progress our troops and the Iraqis have made has the potential to override a measure of caution born of uncertainty," Gates told the House Armed Services Committee. "Our military commanders do not yet believe our gains are necessarily enduring - and they believe that there are still many challenges and the potential for reversals in the future."
Gates also warned that "we should expect to be involved in Iraq for years to come, although in changing and increasingly limited ways."
The Defense secretary said sectarian tensions still exist in Iraq and have the potential to undo recent security progress.
He was testifying one day after President Bush announced that he has approved a plan to withdraw about 8,000 U.S. troops by February. Some troops will leave this fall, but the number of combat brigades in Iraq will remain at the current 15 until late January or early February.
Both Gates and Adm. Mike Mullen, chairman of the Joint Chiefs of Staff, described a new emphasis on Afghanistan, included a greater push to improve the Afghan security forces, and increased pressure on Pakistan to work with Kabul to quell insurgents crossing the border.
Mullen told the panel that while he is not convinced the coalition is winning in Afghanistan, "I am convinced we can."
Under the Pentagon plan Bush approved, one Marine battalion will be sent to Afghanistan in November to replace two that are scheduled to leave, and an Army brigade will deploy to Afghanistan in January, increasing slightly the troop levels there in the coming months.
Rep. Ike Skelton, a Missouri Democrat who chairs the committee, pressed Gates and Mullen on whether the Pentagon is ready to change its repeated assertion that it does what it can in Afghanistan, and does what it must in Iraq - to reflect a new priority for the Afghan fight.
Gates responded that the Afghan fight is more complex, because there are more diverse enemies as well as a broader, more complex coalition fighting them.
"I would say we are reducing our commitments in Iraq and we are increasing our commitments in Afghanistan," he said.
Neither Gates nor Mullen would detail how many more troops can be sent to Afghanistan next year beyond the announced Marine battalion and Army brigade, or how quickly. But they acknowledged that those two units will not meet the requirements voiced repeatedly by commanders in Afghanistan - who have said they need as many as three additional combat brigades, or roughly equal to 10,000 more troops.
"It's going to be a while before we get them there," said Mullen.
Mullen, meanwhile, said it is critical that other federal agencies provide much needed additional civilian support in Afghanistan, including for provincial reconstruction teams. Defense leaders made similar arguments in the past for the teams in Iraq - urgently pressing for representatives from the Agriculture, Commerce and Justice departments to help with the reconstruction and economic rebuilding.
Without a broad interagency approach, Mullen warned, "No amount of troops in no amount of time can ever achieve all the objectives we seek. And frankly we are running out of time."
Requests for interagency assistance have often proved difficult to fill.
Panel members pressed Gates and Mullen on whether the latest troop changes may tie the hands of the next commander in chief. Both said no.
The next president, said Gates, will have complete flexibility and be "constrained only by his view of our national security interests." He added that he hopes the next administration will listen to the advice of its military leaders.
AP Military Writer Robert Burns contributed to this report.