He dealt with the experience in his most recent book Quicksand: What It Means To Be A Human Being.
His best-selling mystery novels, which follow policeman Kurt Wallander through Sweden and Mozambique, were turned into a TV drama starring Kenneth Branagh.
BBC Entertainment Live: News updates
The original, Swedish version of the drama starred Krister Henriksson in the title role, and was screened in the UK on BBC Four.
Born in February 1948, Mankell wrote dozens of plays, novels, children`s books and screenplays. But it was for his Wallander series that he was most renowned.
The rumpled and gloomy detective got his name when Mankell ran his finger through a telephone directory, but went on to sell more than 40 million books.
`More popular`
Wallander first appeared in 1989`s Faceless Killers, investigating a murder in which the only clue is that the perpetrators appear to have been foreigners. When that information was leaked to the public, it triggered a series of racially-motivated attacks in Sweden.
At first, the author was unaware he had created a recurring character, "but then I realised after two or three novels that I had this… instrument who could be useful".
Speaking to the Telegraph in 2011, he said: "I wanted to show how difficult it is to be a good police officer. But after, I think, the third novel, I spoke to this friend of mine and asked what sort of disease I could give him. Without hesitating, she said: `Diabetes!` So I gave him diabetes and that made him more popular.
"I mean, you could never imagine James Bond giving himself a shot of insulin, but with Wallander it seemed perfectly natural."
Mankell divided his time between Sweden and Mozambique, where he ran a theatre company and devoted time to the fight against Aids.
He was active in the "memory books" project, which encourages parents with HIV to record their stories, not just for their children but for future generations.
Shortly after New Year 2014, the author went to see an orthopaedic surgeon in Stockholm with what he assumed was a slipped disc. But tests revealed a tumour in his lung, another in his neck, and evidence the cancer had spread throughout his body.
"It was a catastrophe for me," he told US radio station NPR last year. "Everything that was normal to me up to that point was gone all of a sudden. No one had died of cancer in my family. I had always assumed I`d die of something else."
He leaves his wife of 17 years, Eva Bergman, the daughter of Ingmar Bergman`s second wife, the dancer Ellen Lundstrom.
More about: