Johannes Eisele/AFP/File
The unnamed man was brought up a Muslim but after arriving in Britain in 2007 at the age of 16 gradually lost his faith, according to the university whose law school helped his case.
His leave to remain was due to expire in 2013 but he feared being sent back to Afghanistan, where he risked being prosecuted for abandoning his faith.
The man's case was taken up by Kent Law Clinic, a free service provided by students from the University of Kent and supervised by qualified lawyers.
Claire Splawn, the undergraduate law student who prepared his case, said they argued that an atheist should be entitled to protection "in the same way as a religious person is protected."
Her supervisor, Sheona York, added that they were "absolutely delighted for our client", who had originally come to Britain after a conflict with his family.
"We believe that this is the first time that a person has been granted asylum in this country on the basis of their atheism," she said.
"The decision represents an important recognition that a lack of religious belief is in itself a thoughtful and seriously-held philosophical position."
In a submission to the Home Office, the lawyers included detailed evidence that the man's return to Afghanistan could result in a death sentence for being an apostate unless he remained discreet about his atheist beliefs.
They argued that remaining discreet would be virtually impossible, however, because every aspect of daily life and culture in Afghanistan is permeated by Islam.
A Home Office spokeswoman refused to comment on an individual case, but said Britain had a "proud history" of granting asylum to those who needed it.
Andrew Copson, chief executive of the British Humanist Association, welcomed the government's action.
"Freedom of belief for humanists, atheists and other non-religious people is as important as freedom of belief for the religious, but it is too often neglected by Western governments who focus too narrowly on the rights of Christians abroad, as we have seen recently," he said.
"It is great to see Britain showing a lead in defending the human rights of the non-religious in the same way."