Mr Joyce has previously been loyal to the government
A former army major has resigned as a parliamentary aide to Defence Secretary Bob Ainsworth, criticising the government's strategy in Afghanistan.
Falkirk MP Eric Joyce said the UK could no longer justify the growing casualties in Afghanistan by saying the war would prevent terrorism back home.
The government should set a time limit on the deployment of troops, he added.
Gordon Brown said the Afghan mission was "vital" for fighting terrorism and nothing should distract from it.
The resignation comes on the day the Ministry of Defence announced the deaths of two more soldiers in Afghanistan, taking the number of service personnel killed there since operations began in 2001 to 212.
It also comes on the eve of a major speech by Gordon Brown on the UK's mission there and amid reports that the US is preparing to send more troops to the country.
In his resignation letter, Mr Joyce questioned public support for the mission in Afghanistan and the government's arguments for the presence of troops there.
ERIC JOYCE FACTFILE
Eric Joyce spent 21 years in the Army, including time as a private in the Black Watch and as a major in the Royal Army Education Corps. He left in 1999.
A year later, he was elected MP for Falkirk West in a by-election.
He has served as an aide to four ministers including two defence secretaries and has been a strong supporter of the wars in Iraq and Afghanistan.
Last month he criticised the government's decision to appeal against compensation awards for two wounded soldiers, calling the move "bonkers".
He also cast doubt on Labour's ability to win the next election unless it got a "grip on defence".
"I do not think the public will accept for much longer that our losses can be justified by simply referring to the risk of greater terrorism on our streets," he said.
"Nor do I think we can continue with the present level of uncertainty about the future of our deployment in Afghanistan."
Mr Joyce said the UK must consider an exit strategy for its troops, arguing that personnel numbers should be cut substantially in the next Parliament.
There are currently more than 9,000 UK troops in Afghanistan.
"We need to make it clear that our commitment in Afghanistan is high but time limited," he said.
Mr Joyce also criticised the contribution of other Nato countries in Afghanistan, arguing that the UK "punched a long way above its weight" while "many of our allies do far too little".
"For many, Britain fights, Germany pays, France calculates, Italy avoids," he said.
The political consensus in the UK over the Afghan mission has broken down in recent months with opposition parties questioning whether troops are sufficiently equipped to do the job asked of them in fighting the Taliban.
Critics have said they are being hampered by an acute shortage of helicopters but ministers say army chiefs have all the resources they have requested.
During a surprise visit to Afghanistan last weekend, the prime minister promised more support for UK troops, focusing on greater protection from roadside bombs.
Reports of widespread irregularities in last month's presidential elections and claims of vote-rigging in the ballot - won by President Karzai - have caused dismay in London and Washington.
Mr Joyce said there must be a second round of voting to reassure the British public that the Afghan government "has been properly elected and has clear intent to deal with the corruption there which has continued unabated in recent years".
He also said the well-being of British troops in Afghanistan needed to be given the "highest political priority".
"Above all, Labour must remember that service folk and their families are our people. We say that we honour them for their risk, bravery and sacrifice and we must, at literally all costs, continue to show that we mean it."
In response, Mr Ainsworth said it was "vital" that those in charge of policy were "fully committed" to the mission in Afghanistan.
Mr Ainsworth said Mr Joyce was entitled to his opinion but he did not "recognise" the picture he painted of the situation in Afghanistan.
"Our mission in Afghanistan is vital to our national security. We will not walk away from that responsibility."
Lord West 'surprised' at resignation
Security minister Lord West told the BBC he was "surprised" and "sad" by the resignation and warned that setting a timeline for the withdrawal of British troops could be highly dangerous.
The BBC's political editor Nick Robinson said the prime minister had a political fight on his hands to convince the public and some of his own MPs that the UK and its coalition partners could make a success of the mission in Afghanistan.
The Conservatives said the government was failing to put the case for the UK's continued involvement in Afghanistan.
Shadow defence secretary Liam Fox said there was a "great deal of disquiet" on Labour benches about the situation there.
Liberal Democrat leader Nick Clegg said: "Eric Joyce confirms what I have been saying for a long time, our approach in Afghanistan is over-ambitious and under-resourced."
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.