Proposals for British soldiers to get life sentences for desertion have been criticised as "inhuman and barbaric".
The Armed Forces Bill is being considered by MPs
John McDonnell led Labour backbench calls to scrap the life imprisonment provision of the Armed Forces Bill.
He argued the plan was part of a crackdown on soldiers opposed to the war in Iraq, but his proposal was later rejected by MPs by 442 votes to 19.
Defence minister Tom Watson said life could apply only where desertion was "to avoid relevant service".
The bill aims to create a single system of law for the armed forces.
"It's the life imprisonment that appears to me to be inhuman and barbaric," Mr McDonnell said during debate in the Commons.
The bill was "really about the war in Iraq", he added, saying the number of "abscondees" in the military had trebled since the invasion.
"I believe that legislation of this sort will fail," he said.
"No increase in severity of punishments will prevent servicemen and women from speaking out."
Instead, he called for a maximum desertion penalty of two years, a proposal opposed by many opposition and Labour MPs.
Labour's Harry Cohen agreed that "we should take this opportunity now to get rid of this excessive sentence that can be applied to people who have serious conscientious objections to the war in Iraq".
Nick Harvey, for the Liberal Democrats, said that "in almost all circumstances life imprisonment would be way over the top as a penalty".
But he said Mr McDonnell's desire to change desertion from "a serious offence" to one punishable by a maximum two-year sentence "would not be desirable".
And Labour's Kevan Jones backed the life sentence sanction, saying there must be controls over people who had made a decision to join the armed forces.
"We can't have a pick and choose army where people pick and choose where they do serve," he added.
Defence minister Tom Watson said there would only be a maximum sentence of life where desertion was "to avoid relevant service".
That would exclude things like military occupation of a foreign country.
Relevant service operations would be "the ones which every member of the force needs to have complete confidence in the other members of his unit," he added.