Greiner was reportedly freed in Gao region in the country's northern desert, where dozens of people were reported killed this month in clashes between the Malian army and al-Qaeda fighters.
Switzerland's foreign ministry said that he had received medical attention and would be heading home soon.
"The Swiss foreign ministry learnt with joy that the efforts towards the liberation of the last Swiss hostage in Mali has been successful," it said in a statement.
"The last hostage has been freed in Mali. The Swiss citizen has been taken care of medically and will be repatriated to Switzerland to rest"
Swiss foreign ministry
"The last hostage has been freed in Mali. The Swiss citizen has been taken care of medically and will be repatriated to Switzerland to rest."
An official involved in negotiations with the kidnappers in northern Mali told the AFP news agency earlier this month that the Swiss national was in poor health.
"He is hardly eating at all. He is suffering a lot. We are very worried," he said.
In May, the Algerian media reported that al-Qaeda was demanding $14.21m in exchange for Greiner and Dyer.
It was not immediately clear on Sunday whether a ransom had been paid for the release of the Swiss national.
Al-Qaeda in the Islamic Maghreb emerged out of the Salafist Group for Preaching and Combat, an Algerian Islamist movement.
The group now operates across a vast stretch of the Sahel region of northern Africa.
Amadou Toumani Toure, Mali's president, announced an all-out war on the group after Dyer's execution and there has been fierce fighting in subsequent months.