Ed Miliband promised swift action from a Labour government to beef up legal sanctions to protect the armed forces from assault and discrimination in the UK as he met troops in Afghanistan.
The Labour leader used a visit to Camp Bastion to promise new legislation within a year of taking office if the party wins the 2015 general election.
With UK forces due to be withdrawn by the end of the year, Mr Miliband said they should take pride in what they had achieved but cautioned that the job was "not yet done".
Critics have raised concerns that international support for Afghanistan and its civilian population will not be sufficiently maintained once the Nato-led mission has been wound down.
"We will not let the heroism and bravery of our armed forces be forgotten once Afghanistan has dropped from the headlines," Mr Miliband told personnel.
"We as a party and as a government will be committed to recognising the unique place of the armed forces in our society.
"That is why today I want to tell you that we are committed to changing the law to make it a specific criminal offence to assault a member of the armed forces, and to outlaw discrimination against service personnel and veterans.
"Men and women in the Army, Navy and RAF serve us with dignity and bravery. It is our duty to ensure they are treated with dignity in return."
Labour frontbencher Thomas Docherty introduced an Armed Forces (Prevention of Discrimination) Bill to the Commons as a Private Member's Bill - backed by the party leadership.
It stands virtually no chance of becoming law but Mr Miliband is committed to introducing it as a government measure if he becomes prime minister.
Physical or verbal assaults motivated by someone's membership of the military would become an aggravated offence.
Protection against discrimination presently afforded disabled people, religious groups and members of ethnic minorities would be extended to personnel.
And there would be a legal ban on serving members and veterans being refused access to shops, restaurants, hotels, pubs and other services on the grounds of their service.
Defence Minister Anna Soubry has told MPs the Government was alert to the issues but "not aware of any increase and we are not aware of any problem".
One recent survey suggested that one in five had been subject to verbal abuse, 18% refused service in hotels, pubs or restaurants simply for wearing their uniforms, and 6% victims of violence or attempted violence.
Mr Miliband's visit comes days after the first death of a UK soldier in the country in 2014, which is due to be the last year of the military campaign against the Taliban which began in 2001.
The drawdown of British troops is under way, and all combat troops are due to have left by the end of the year.
"As our military operations draw to an end, you and everyone who has served in Afghanistan can take pride in what has been achieved here," he told them.
But he said it was important for politicians to recognise that " the job here is not yet done".
"There is an urgent need for reconciliation between the different parties in Afghanistan and for the presidential elections to pass off peacefully.
"There is a long-term challenge to reconstruct and develop Afghanistan, which is why we are committed to keep funding work to rebuild this country for years to come.
"You know and we know many of our troops have made huge sacrifices, including the ultimate sacrifice.
"We honour them and we honour all those who have made the served here if we keep building to create a more secure, more stable and more prosperous Afghanistan."
An MoD spokesman said: "The men and women of our armed forces reflect what is best in our society and any discrimination against them is unacceptable.
"We have worked hard to ensure our armed forces, veterans and families have the support they need and are treated with the dignity they deserve.
"That is why we enshrined the Armed Forces Covenant in law and since then almost 400 local authorities have signed up to pledge their support locally and around 80 companies have already shown an interest in joining the new Corporate Covenant.
"This shows the immense amount of respect and gratitude there is for our armed forces across society and we would encourage anyone else who wants to show their support to sign a local Community Covenant or join the Corporate Covenant."