Vendors sell their wares near an election poster of former Nigerian military ruler Muhammadu Buhari before the start of the All Progressives Congress (APC) party convention in Lagos in this December 10, 2014 file photo. (Akintunde Akinleye/Reuters)

AFRICA’S MOST populous nation may be careening toward trouble. While Nigeria has recently captured international headlines for its battle against the murderous terrorist group Boko Haram, the most immediate threats to the country’s stability are not bullets from Islamist militants, but ballots.

In February, Nigeria, home to almost 200 million people, will hold what will essentially be the first electoral contest between the country’s two major parties, the incumbent People’s Democratic Party and the All Progressives Congress. The PDP has won every election since Nigeria transitioned from military to democratic rule in 1999, but the APC, formed last year from a coalition of opposition parties, threatens its dominance. This is a sea change in a political landscape already inflamed by north-south tensions, an overly militarized political culture and pressure on the economy due to falling oil prices. Add to the mix the Boko Haram threat and the nation’s ill-prepared electoral commission, and the country has a recipe for an explosive general-election season.

Nigeria’s 2011 elections, which were judged to be fair by international monitors, were nevertheless very violent, leaving more than 800 people dead in 12 northern states. After northerner Muhammadu Buhari, a former general, lost that election to current president Goodluck Jonathan, many northern Muslim protesters targeted Christians and people perceived to be from the south. In Christian towns, mobs answered by killing Muslims and setting mosques ablaze. There are disturbing signs that this year’s campaign could prompt an escalation. Reports have surfaced of an unprecedented influx of illegal arms trafficked into the country ahead of the elections, especially in the oil-rich Niger Delta (which includes Mr. Jonathan’s turbulent home state) and in the northeast. State and local politicians have taken to arming their supporters.

The contest will be close. Many Nigerians have been unhappy with Mr. Jonathan’s handling of state corruption and his failures to contain Boko Haram’s violence. His APC opponent will again be Mr. Buhari, a Muslim with a substantial popular following.

To minimize the risk of post-election violence, the Nigerian government must first do more to support its electoral commission; there have been serious doubts about its readiness to organize the registration and voting process. Less than six weeks ahead of elections, the federal government has yet to approve the commission’s budget. Millions of permanent voting cards have not yet been distributed.

Mr. Jonathan should also avoid misusing military and police forces before, during and after the election. The Nigerian army, which was in power from 1966 to 1999, still holds a massive amount of influence over political affairs and has been accused of abuses in past elections. State security forces must protect human life and security first and foremost and cannot be used as a tool of the incumbent party.

The United States and other Western governments ought to press Mr. Jonathan as well as his opponent to respect the rule of law. The government must prioritize peace, not power, if Nigeria is to weather this particularly dangerous stress test.