Under Swiss law a refugee can be deported even after many years in Switzerland if he is deemed a threat to security or public order.
In this case the Fribourg resident, who has spent 25 years in Switzerland and does not know his country of origin, appealed to the cantonal court after the authorities revoked his residency permit in 2015 following a number of convictions for violent behaviour.
But last month the court rejected his appeal, Swiss media reported on Tuesday.
The man arrived in Switzerland with his family in 1992. They were granted asylum and set up home in the canton of Fribourg, according to news agencies.
As a minor, the young man was three times convicted of violent offences, behaviour that continued into adulthood and led to a three-year prison sentence in 2010.
A year after being released he reoffended and was handed another two-year sentence.
Ruling on the man's appeal against his deportation, the cantonal court said there was a high risk that he would reoffend, based on the speed of his previous reoffending, his aggressive behaviour in prison and the opinion of a psychiatrist.
The defendant said he had no relationship with Afghanistan, that he didn't know the language or the country's customs.
The current fragile situation in Afghanistan and the fact he was from an ethnic minority also formed part of his argument against his deportation.
However the court drew on the opinion of the Swiss migration office (SEM) which in 2015 said it found no reason to think the man would be treated inhumanely if he returned to Afghanistan, mainly because so much time had passed since the events that led to him and his family fleeing the country as refugees.
The public interest in deporting him outweighed his private interest in staying here, concluded the judges.
It's not only refugees who can be deported from Switzerland for committing crimes.
This year a new law came into force which allows the deportation of any foreigner who commits a serious crime warranting at least a three-year sentence, such as murder, rape, violent acts, armed robbery and drug trafficking.
The new measures, applicable to crimes committed after October 1st 2016, were introduced after the Swiss public approved a popular initiative on the subject in a 2010 referendum.
However in an amendment to the text of the original initiative, the government deemed that the courts should have the power to make exceptions, if the expulsion puts the foreigner in a dangerous situation or if a reason for the person to stay outweighs the public interest for expelling them.
The amendment – heavily criticized by the anti-immigration Swiss People's Party (SVP) – aimed to protect the interests of 'secondos', those born in Switzerland but without Swiss citizenship.
In February 2016 Swiss voters rejected another SVP-led initiative that called for the automatic deportation of foreigners guilty of even minor crimes.
If passed, the controversial proposal would have dramatically increased the number of offences that can get foreign nationals automatically kicked out of Switzerland, including crimes usually punishable with short prison sentences or fines.
It would also have removed a judge's right to make exceptions.
Opponents had warned that if the text passed, ‘secondos' risked being deported to countries they have never lived in, just for petty offences.