HOW does a big oil producer end up with no fuel? The irony of that predicament is not lost on citizens of the country with sub-Saharan Africa’s largest oil reserves. They endure hours-long queues at petrol stations and buy on the black market. Yet few recall a scarcity as severe as the one that peaked this month.

Drivers turned to greasy hawkers who demanded up to six times the official price for their cans of contraband. Traffic petered out in Lagos, a clamouring city of some 20m people. Local airlines cancelled flights and international carriers began diverting through other West African capitals for fuel. Since diesel and petrol are also needed to generate electricity (mainly using backyard generators, since government networks are pitiful), darkness descended on homes. Shops and offices closed and radio stations went off the air. Banks shut early, and mobile-phone companies warned of network outages. Africa’s largest economy ground almost to a halt.

For a country that churns out roughly 2m barrels of oil a day, this is a scandal. The chief cause is Nigeria’s inability to process its crude. Corruption and mismanagement have left its four state refineries to rot, forcing this fuel-guzzling country to import up to 80% of its needs.

At the heart of the rot is a controversial subsidy scheme under which the government pays wholesalers the difference between the open-market cost of fuel and a fixed pump price of 87 naira ($0.43). It is billed as protecting the poor, who see cheap fuel as the sole perk of their country’s oil riches. In practice the subsidy is a mechanism for corruption by complex networks of retailers, workers at the Nigerian National Petroleum Corporation (NNPC) and government officials. They embezzle billions of dollars by overstating their imports and pocketing the difference. At its peak in 2011, it was reckoned to cost the government $14 billion annually.

The latest shortage began when importers slowed deliveries, saying the government owed them $1 billion in backdated subsidy payments. Without those, they said they could no longer afford to import fuel. Critics responded that they were trying to bleed the government dry ahead of a transfer of power to the incoming administration of Muhammadu Buhari on May 29th, amid speculation that he may reduce or indeed terminate the subsidy.

Mr Buhari, who inherits the crisis, is ironically one of its fathers: he set up the NNPC during his time as petroleum minister in the 1970s. In 2012 the outgoing government tried to eliminate the subsidy but backtracked on reform in the face of violent protests. It had the perfect opportunity to take a second shot earlier this year, when oil prices were at their lowest. Yet President Goodluck Jonathan tried to curry voters’ favour by cutting prices even further.

Those getting fat off the scheme will fight—perhaps literally—to save it. An investigation into subsidy payments launched by Ngozi Okonjo-Iweala, the finance minister, in 2011 “led directly to the kidnap of her mother,” her spokesperson claims. Reforms are not popular with the masses, either. Although subsidies disproportionately benefit the rich, who drive bigger cars and buy more fuel, prices for petrol, transport and food would all rise.

Yet Nigeria’s popular new president has more political capital than his predecessor. Citizens are better informed about the theft surrounding the scheme. A phased withdrawal that is explained carefully to voters and balanced by social grants or investment in infrastructure might work.

Abolishing the subsidy might also give local refining a boost. Official prices are now so low that no refiner can compete. Tight government finances may force the change. Roughly $5 billion was allocated to subsidies in 2014. This year’s budget makes provision for a fraction of that amount. Low oil prices left a dent in government revenues. Foreign reserves have fallen; a crude-oil savings account is all but empty; and the currency has tanked. A cash-strapped government can no longer afford such a corrupt and costly racket.