Shehu Shagari, who has died aged 93, was a rare consensual figure in Nigerian politics and the country’s president from 1979 to 1983.

He took office at the behest of the military, which sanctioned a return to civilian government after its own repeated interventions had prevented democracy taking root in Nigeria in the first two decades following independence from Britain in 1960.

Typically, the army brought an end to Shagari’s rule in a coup not long after he was re-elected in 1983. The coup leader, Maj Gen Muhammadu Buhari, is himself now the civilian president of Nigeria following his own election victory in March 2015.

A devout Sunni Muslim from northern Nigeria, Shagari – customarily dressed in Islamic robes – cut a contrasting figure to the bemedalled military men seen in almost constant attendance during his presidency. But for many senior officers, Shagari, with his reputation as a mild-mannered conciliator without a known agenda or power base of his own, was the ideal leader to take office under a new constitution, modelled on that of the US, which gave significant powers to Nigeria’s 19 federal states.

Forging national unity was to be Shagari’s aim in a country riven with ethnic tensions that had been highlighted by the bitter (Biafran) civil war of the late 1960s.

Shagari’s presidency would be marked by the two issues so familiar to contemporary Nigerian politics: endemic corruption and the often fierce divisions between northern Muslims and southern Christians.

But he was also singularly unfortunate to become president at a time when the global glut in oil – Nigeria’s main commodity – sent prices tumbling, slashing the revenues available for Shagari to deliver on his election promises to raise the population’s living standards.

His reputation in the region was severely damaged by his expulsion of more than a million, mostly Ghanaian, workers, who were accused of outstaying their visas and taking jobs from Nigerians.

Internationally, Shagari used high-profile visits to the US and Britain to highlight Nigeria’s opposition to the apartheid regime in South Africa. On his first overseas visit to Washington he found a sympathetic host in President Jimmy Carter. During a state visit to Britain in 1981, he called on Margaret Thatcher’s government to do more to combat “the horrible state of affairs” in South Africa.

Shagari was born in the north-western state of Sokoto in the village founded by his great-grandfather from which the family took its name. He grew up in a polygamous family and his father was a farmer and trader. After studying at a Koranic school he was educated at Barewa College (then known as Kaduna College), in Zaria, Kaduna state.

Shagari worked briefly as a teacher before entering local politics in 1951. Three years later he was elected to the (still colonial) federal House of Representatives. Following independence in 1960, Shagari was a member of every administration – serving variously as minister for the economy, pensions and internal affairs – up until 1966 when the army stepped in to end civilian rule for the first time.

Shagari went back to Sokoto and served in local administration before returning to Lagos in 1971 to become federal commissioner for economic development under the military head of state, General Yakubu Gowon. He would go on to be Gowon’s civilian finance minister, building links with the World Bank and the IMF.

Later in the decade, as a new military leader, Olusegun Obasanjo, unveiled plans for a return to civilian rule, Shagari helped found a new political party, the National party of Nigeria. He was chosen by the party to be its candidate in the presidential election held in April 1979.

Under the slogan One Nation, One Destiny and enjoying the backing of many prominent politicians in the north of the country but also significant support in the south, Shagari won a narrow but not undisputed victory. But his election honeymoon was to prove short-lived.

After initial investment in improving infrastructure and building low-cost housing – both election pledges – the fall in oil prices, which began in 1981, severely affected government finances. Shagari took several steps to strengthen the economy, cutting spending, increasing import duties and expelling foreign workers. Against this background he won re-election in a bitterly contested vote in the summer of 1983. But within a few months, Shagari’s presidency was over: he was deposed in a New Year’s Eve coup.

Accused of being “inept and corrupt”, Shagari was arrested and held for three years. He was later cleared of personal corruption but banned from participation in Nigerian politics. His removal was the prelude to a long period of military rule.

Shagari had four wives, two of whom are reported to have survived him. He is also survived by many children and grandchildren.

• Alhaji Shehu Usman Aliyu Shagari, politician, born 25 February 1925; died 28 December 2018