Elections for the Second Republic were held in July 1979. Most parties received votes along ethnic lines, the exception being the National Party of Nigeria (NPN), which commanded support from several corners of the country and won the most legislative seats. The NPN fell short of a majority, however, and often joined forces with the Nigerian People's Party (NPP), a group led by Dr. Azikiwe. In the presidential elections, NPN candidate Alhaji Shehu Shagari won the largest number of overall votes.

Once in office, the new federal, state, and local governments embarked on ambitious programs of development to cure the weak economy. Although several of the initiatives were productive, many more were expensive and economically unsound. Others were riddled with corruption. In 1982 the world oil market collapsed, leaving Nigeria unable to pay its short-term debts, much less finance the projects to which it was committed. Eventually, the country was also unable to import essential goods.

In January 1983 the government ordered the expulsion of all unskilled foreigners, claiming that immigrants who had overstayed their visas were heavily involved in crime and were taking jobs from Nigerians. Between 1.5 and 2 million people, the majority of them Ghanaian, were forced to leave in less than two weeks. The move popularly known as 'Ghana must go' was widely condemned, especially by West African states, although it proved very popular in Nigeria. In the elections of 1983, the NPN claimed a decisive victory over several opposition parties, while observers cited widespread instances of fraud and intimidation.

On New Year's Eve 1983, army officers led by Major General Muhammadu Buhari overthrew the Shagari government in a bloodless coup. The coup was seen as a welcome relief by most Nigerians at the time.