Mahdi, whose civilian government was overthrown in a 1989 coup that brought President Omar al-Bashir to power, flew in to Khartoum, said his daughter Mariam al-Mahdi, deputy head of the Umma party.
She said authorities had prevented several supporters from entering the airport to welcome Mahdi.
But Mahdi later spoke before thousands of supporters who had gathered in Khartoum’s twin city of Omdurman.
“I came back to end the war, re-establish peace and work for a democratic transition,” he told them.
“I will work with all the parties in order to put an end to hostilities and to see that humanitarian aid reaches all those who need it.”
Mahdi left Sudan for exile, mostly in Egypt, in August 2014, weeks after being released from prison following a month in custody on treason-related charges that carried the death penalty.
The 81-year-old had been arrested after accusing pro-government paramilitary forces of rape in western Sudan’s Darfur region where the UN says at least 300,000 people died in a conflict that erupted in 2003.
His detention led to large-scale protests at the time calling for the fall of Bashir’s government, which were violently dispersed by authorities.
The case sparked concern from Western governments but Mahdi was released after his legal team appealed to the justice minister to drop or suspend the charges. The exact status of the charges is not clear.
A fixture of Sudanese politics since the 1960s, Mahdi was prime minister from 1966 to 1967 and again from 1986 to 1989.
His government was the last one to be democratically elected in Sudan before the 1989 coup launched by Bashir.
The Umma party is one of Sudan’s oldest political institutions.
Mahdi is also revered by followers in his Ansar al-Islam movement, a key component of the party.
– ‘Reconciliation deals’ –
While in exile Mahdi signed a controversial agreement joining Umma in an alliance with other opposition parties and a number of rebel groups from the war-torn Blue Nile, South Kordofan and Darfur regions.
In a statement issued in November, Mahdi had urged workers to stage a three-day nationwide strike against Bashir’s regime, amid mounting anger over fuel subsidy cuts and other economic problems.
Bashir, who is wanted by the International Criminal Court on charges of war crimes and genocide related to the Darfur conflict, has been accused of systematic repression of the opposition.
The conflict — which also displaced 2.5 million people — erupted in 2003 when ethnic minority rebels took up arms against Bashir’s Arab-dominated government, accusing it of marginalising the region.
Sudanese lawmakers voted in December to bring back the post of prime minister, a position abolished after Bashir’s Islamist-backed putsch against Mahdi in 1989.
In October, after a quarter-century in power, Bashir concluded a year-long national dialogue aimed at resolving the insurgencies in Sudan’s border regions and healing the country’s crisis-wracked economy.
The talks, launched in October 2015, were boycotted by most mainstream opposition and armed groups.
On Thursday, Mahdi repeatedly called for reconciliation in Sudan through a political dialogue.
“During my stay abroad, I succeeded in persuading my friends within political parties of the need for a political solution,” he said.
He also announced that he would soon criss-cross the country in order to strike “reconciliation deals and put an end to tribal rivalries”.