According to Sweden's Expressen newspaper, Gustafsson landed at Stockholm's Arlanda airport late on Monday afternoon, where he was welcomed by his family.
The kidnappers had previously demanded five million USD for his release, something which had been rejected.
Speaking to Swedish Radio News, Swedish Foreign Minister Margot Wallström said:
It is with enormous joy I can inform you that Johan Gustafsson has been released and can be reunited with his family. We achieved this following a co-operation between the Swedish Foreign Ministry, the Swedish police's national operative division, and Swedish and foreign authorities. I have spoken with Johan, he is in good spirits and overwhelmed by what has happened."
Gustafsson was kidnapped in November 2011 in the middle of a motorcycle trip between Stockholm and South Africa.
Terrorists seized him, Sjaak Rijke from the Netherlands, and Stephen McGown from South Africa, during a raid on a restaurant in the historic tourist town of Timbuktu.
A German man was killed in the attack.
The kidnappers claimed allegiance to the terror group Al-Qaeda in the Islamic Maghreb (AQIM).
In May, Gustafsson had been held for 2,000 days.
The South African charity Gift of the Givers, which has worked hard over the past two years to secure the release of both Gustafsson and McGowan, said they had nothing directly to do with his release.
Imtiaz Sooliman, who leads the charity, said she did not know whether McGown had also been released.
Gustafsson's family have received only sporadic information since the kidnapping.
The kidnappers released a video in 2013, in which Gustafsson said he was being treated well. Later in 2013, he was interviewed in captivity by the Al-Jazeera television network.
There was then a gap of two years before a new video was uploaded to YouTube, in which Gustafsson is shown asking his kidnappers about progress in the ransom negotiations.
Rijke was freed during a raid by French armed forces in 2015.