KABUL, Afghanistan — The Afghan government faces a peculiar problem in at least two major provinces: It provides precious electricity, some of it imported at costly rates from neighboring countries, but Taliban militants collect most of the bills.

If the government cuts off power, it will further anger a population that is already disenchanted. If it does not, the revenue from the power will continue to provide more income to an already emboldened Taliban.

The Taliban, fighting the Afghan government and a large international military coalition, have long tapped into Afghanistan’s lucrative drug trade and illegal mining, in addition to the streams of donations they receive from supporters abroad, mainly in the Persian Gulf states.

But as they have taken over increasingly large areas in the past two years, they have found new ways of diversifying and collecting revenue, according to interviews with officials, Taliban commanders and local residents.