Gunmen stormed the headquarters of Libya’s national oil company in Tripoli on Monday, setting off explosions, taking hostages and spraying gunfire, leaving several people dead or wounded before forces aligned with the government took control of the building. The identity and motives of the assailants were not clear.

The oil company said two of its employees had been killed, and there were reports of two gunmen killed, putting the total number of dead at four. But an employee who escaped the assault said he believed that as many as six people had been killed, including three of the assailants.

The attack follows a month of escalating violence among rival militias competing for control of Tripoli, the capital, where a United Nations-backed government has its headquarters but remains largely powerless. Last week, clashes killed more than 60 people.

Any attack on the national oil company is significant because petroleum is the lifeblood of the Libyan economy, and competition for control of the country’s vast oil reserves is at the heart of the often violent struggle for power there. Cuts in oil revenue because of the fighting have driven Libya into a severe financial crisis, with the government failing to meet the public payrolls, long lines forming at banks, and inflation soaring.