In a high-profile speech in London, hastily arranged following a series of British deaths in Afghanistan this week, Mr Brown said the military action in the country was "our first line of defence" against terror attacks at home.

Paying tribute days ahead of Remembrance Day to the 93 British troops who have died in Afghanistan this year, the Prime Minister said: "These men are our heroes today."

Mr Brown acknowledged that Britain's strategy was not "without danger or risk".

But he warned that al Qaida terrorists continue to plot terror attacks on Britain from the region, and said: "This mission must not fail."

Mr Brown’s speech comes amid polling evidence suggesting that a growing majority of voters now want to see British troops withdraw from Afghanistan within the coming year - with more than half in a survey this week saying they did not believe victory against the Taliban insurgents was possible.

And it follows a call from former Foreign Office minister Kim Howells for the mission in Afghanistan to be halted and the money spent on anti-terror measures in the UK.

In a clear response to Dr Howells’ call, Mr Brown said he rejected any suggestion that the commitment in Afghanistan was diverting effort away from security at home.

“Britain has consistently shouldered its fair share of the burden and more - especially in the last three years, since we deployed into Southern Afghanistan, the heartland of the Taliban,” he said.

“But when the main terrorist threat facing Britain emanates from Afghanistan and Pakistan; and when, although the sustained pressure in Pakistan, combined with military action in Afghanistan, is having a suppressive effect on al Qaida, we know that they continue to train and plot attacks on Britain from the region ... this mission must not fail.

“It is not easy; the choices are not simple. There is no strategy that is without danger and risk.

“But that is the responsibility of leadership - of government, and of our armed forces. To do what is necessary, however difficult, to keep the British people safe. We cannot, must not and will not walk away.”

Mr Brown said that in discussions over the past few days, he had agreed a set of measures with Afghanistan President Hamid Karzai to improve the country’s security, governance, political settlement, economic development and relations with neighbours like Pakistan.

He warned today that if Mr Karzai’s government failed to fulfil these requirements, “it will have forfeited its right to international support”.

Admitting that the evidence of fraud which overshadowed Mr Karzai’s re-election was a “setback”, Mr Brown warned: “I am not prepared to put the lives of British men and women in harm’s way for a government that does not stand up against corruption.”

Mr Brown said the key to bringing British troops home from Afghanistan was building up the home-grown armed forces and police to a state where they could deliver security themselves.

Despite the murder this week of five British servicemen by a “rogue” Afghan police officer they were training, the UK would not give up its role of training and mentoring local security forces.

“We will not give up this strategy of mentoring,” said Mr Brown. “Because it is what distinguishes a liberating army from an army of occupation.

“Not an army in opposition to local Afghan people but an army supporting local Afghan people.”

In an apparent acknowledgement of criticisms that he has not successfully explained his strategy in Afghanistan to voters, Mr Brown concluded: “What people here in Britain ask for is the same as our forces on the ground ask for - a clear sense of what success in Afghanistan would look like, and how we will get there.

“My answer is: we will have succeeded when our troops are coming home because the Afghans are providing security themselves, continuing the essential work of denying the territory of Afghanistan as a base for terrorists.

“The right strategy - for Britain and for the international community as a whole - is the one that enables the Afghans to take over from international forces sooner; at a higher level of capability; and with a greater level of assurance that the pressure on al Qaida and other terrorist and extremist groups will be maintained, and so that a safer, more stable and better-governed Afghanistan will contribute to a safer Britain - in a safer world.”