Mr Gates said talks were needed with the Taleban to resolve the conflict
US Defence Secretary Robert Gates has rejected as "defeatist" a comment by a top British commander in Afghanistan that the war there cannot be won.
Mr Gates said despite challenges, there was no reason to think success could not be achieved in the long run.
But he endorsed the recommendation by Brig Mark Carleton-Smith that a resolution to the conflict would require negotiations with the Taleban.
Earlier, Nato-led forces said they also supported opening talks with militants.
Brig Richard Blanchette, the spokesman for the International Security Assistance Force (ISAF), said there could be no military solution.
The UN Special Representative in Afghanistan, Kai Eide, made similar comments.
"We all know that we cannot win it militarily. It has to be won through political means. That means political engagement," he said.
Speaking on board a flight to Budapest to meet Nato defence ministers, Mr Gates rejected the assertion made by Brig Carleton-Smith that a "decisive military victory" should not be expected.
"While we face significant challenges in Afghanistan, there certainly is no reason to be defeatist or to underestimate the opportunities to be successful in the long run," he said.
But Mr Gates agreed that part of the solution to the conflict would involve talks with members of the Taleban who are willing to work with the Afghan government.
"What we have seen in Iraq applies in Afghanistan," he added, referring to a successful programme to persuade Sunni Arab tribesmen who had previously fought against the government to turn against al-Qaeda in Iraq.
"Part of the solution is strengthening the Afghan security forces. Part of the solution is reconciliation with people who are willing to work with the Afghan government."
Mr Gates said he would again press Nato members to send more troops to Afghanistan during the meeting in Hungary.
"I want to make sure that everybody understands that the increase in US forces is not seen as replacements for Nato contributions, but as reinforcement," he said.
On Sunday, Brig Carleton-Smith, the British commander in Helmand province, said the aim of the Nato-led mission was to ensure the Afghan army would be able to manage the country on its own.
Brig Carleton-Smith said the war in Afghanistan cannot be won
He said this could involve discussing security with the Taleban.
When international troops eventually leave Afghanistan, there may still be a "low but steady" level of rural insurgency, he conceded.
He said it was unrealistic to expect that multinational forces would be able to wipe out armed bands of insurgents in the country.
"If the Taleban were prepared to sit on the other side of the table and talk about a political settlement, then that's precisely the sort of progress that concludes insurgencies like this," he told the Sunday Times newspaper. "That shouldn't make people uncomfortable."
The BBC's Martin Patience in Kabul says Brig Carleton-Smith's comments echo a view commonly-held, if rarely aired, by British military and diplomatic officials in Afghanistan.
Many believe certain legitimate elements of the Taleban represent the positions of the Afghan people and so should be a part of the country's future, says our correspondent.