BAGHDAD - Gunmen shot their way into Iraq's largest oil refinery early Saturday, setting off explosions that forced the facility to shut down for at least two weeks, officials said.

Insurgents have attacked pipelines before, but an assault on a facility is rare, if not unprecedented, an industry analyst said.

The attack occurred about 150 miles north of Baghdad in the city of Baiji, known as an insurgent stronghold. Four guards and an engineer were killed.

The refinery produces gasoline for cars and fuel for power plants, and a prolonged shutdown could cause major headaches for the government of Prime Minister Nouri al-Maliki, already under pressure from a gathering protest movement demanding better services.

The country has several days' worth of gasoline in storage but would have to import after that to compensate for a shortage, opening up the possibility of long lines at gas stations and higher prices. The shutdown could also cause problems for power plants, curtailing electricity for people already frustrated with severe shortages.

Yet another concern is the attack's impact on the country's oil industry as a whole, which only recently has begun to spring back to life. The government has been trying to lure foreign investors to build four new refineries, without much success.

"It has been difficult to get international companies to come to construct these," said Ruba Husari, editor of Iraq Oil Forum, which covers the industry. "Now you have another element of risk."

Iraq refines about 550,000 barrels of oil a day, and the Baiji facility accounts for about half of that.

From 2004 until late 2007, Sunni insurgents controlled the facility, using proceeds to finance their operations.

The attack occurred at 3 a.m. Saturday, when the gunmen shot their way through a gate, killing the guards and engineer. Guards killed two gunmen, but the rest escaped.

The attackers detonated a bomb in one section of the refinery, but the entire facility will have to be shut down to repair it, officials said.