Ahnlund, who was born in Stockholm, was an expert on 19th and 20th century Nordic, especially Danish, literature. He wrote his doctoral dissertation on Henrik Pontoppidan, and later wrote on Gustav Wied and Sven Lidman, among others. He was also a novelist and published translations of various writers such as Julio Cortázar. He received his doctorate from Stockholm University, and was a professor of Nordic Literary History at the University of Aarhus. He was elected a member of the Swedish Academy in 1983.
Due to conflicts with the former permanent secretary of the Academy, Sture Allén, and his successor, Horace Engdahl, Ahnlund had only participated minimally in the work of the Academy from 1996 until his death in 2012. On 11 October 2005, just a few days before the announcement of the 2005 Nobel laureate for literature, he declared in a piece in Svenska Dagbladet that he would leave the Academy in protest against the choice of recipient of the prize the previous year, Elfriede Jelinek; he characterized Jelinek's work as chaotic and pornographic. As a membership in the Academy is for life, Ahnlund was not able to formally leave the Academy during his lifetime, but did not participate in its work from 1996, and his chair was left empty until his death.
- Henrik Pontoppidan : fem huvudlinjer i författarskapet (1956)
- Vännerna : en berättelse från hem och skola (1963)
- Den unge Gustav Wied (1964)
- Isaac Bashevis Singer: hans språk och hans värld (1978)
- Jordens skönhet : singalesiska minnen och myter (1979)
- Diktarliv i Norden : litterära essäer (1981)
- Karl Ragnar Gierow : inträdestal i Svenska akademien (1983)
- La Real Academia Española (1985)
- Octavio Paz : hans liv och diktning (1990)
- Sven Lidman : ett livsdrama (1996)
- Spansk öppning : essäer om Spaniens och Latinamerikas litteratur (2003)