Updated

Gunmen disguised as police officers seized control of a police station in western Iraq Monday morning, killing four people and taking dozens of hostages before Iraqi forces swept in and ended the standoff, Iraqi officials said.

The three-hour hostage crisis, as well as another attack nearby on a police officer's house, demonstrated the vulnerability of the Iraqi security forces at a time when American troops are swiftly drawing down their presence after more than eight years of war.

Four insurgents wearing explosives vests underneath police uniforms and armed with grenades and pistols with silencers walked into the police compound in al-Baghdadi around 9 a.m., said Brig. Mohammed al-Fahdawi of the Iraqi army's 7th Division in Anbar province. Because the gunmen were wearing police uniforms, they were not searched, he said.

The gunmen shot and killed three police officers, including the director of the police station, and an employee in the mayor's office before seizing weapons held in the police station, said al-Fahdawi, who coordinated the rescue operation.

The gunmen herded the hostages into some of the rooms, said a police officer at the scene who did not want to be identified because he was not authorized to speak to the media.

After the Iraqi army arrived on the scene and exchanged gunfire with the assailants, al-Fahdawi said he ordered his men to storm the building.

The mayor, Muhanad Zbar Mutlaq, was inside at the time.

After hearing the shooting, the mayor grabbed his cell phone and ran into the bathroom next to his office, locking the door behind him. He said he put his cell phone on silent and began sending text messages to Iraqi army officers he knows.

"Some of the terrorists entered my office and one of them picked up my landline phone when it was ringing and said: 'We are the fighters of the Islamic State of Iraq,"' said Mutlaq. The Islamic State of Iraq is a front group for Al Qaeda. Mutlaq said he could tell by the speaker's voice that he was Iraqi.

"When I was rescued I saw blood everywhere with pieces of human flesh of the two terrorists who blew themselves up," he added.

Two of the insurgents blew themselves up when Iraqi police stormed the station to free the estimated 40 people held inside, said al-Fahdawi. Security forces killed the other two assailants, he said.

Deputy governor of Anbar province Dhari Arkan confirmed that the hostage standoff had ended and said four people were killed.

"The security measures here are zero. Some weeks ago terrorists were able to blow up the provincial council and today they were able to break into a police station," he said.

Earlier this month, two suicide bombers blew themselves up in front of the government compound in the Anbar provincial capital of Ramadi, killing four people and wounding eight others.

Insurgents frequently go after Iraqi government targets in an effort to destabilize the security situation, and the Ramadi building has been targeted repeatedly by suicide bombers.

The mayor of the nearby town of Hit, Hikmat Juber, said many of the hostages were government officials working on the second floor of the building.

Gunmen also attacked the home of the police chief in the town of al-Dolab about 10 miles away from al-Baghdadi, said Lt. Col. Mohammed Ismail of the Anbar police media office. He said three gunmen were killed when they tried to storm the house, which is located near the town's police station.

Al-Fahdawi confirmed that attack and said two of the police chief's guards were also killed. He said two gunmen were arrested.

Violence in Iraq is nothing like it was in 2006 or 2007 when the insurgency was at its most vicious. But militants have demonstrated a dogged persistence in carrying out attacks despite repeated crackdowns by U.S. and Iraqi forces.

Anbar is Iraq's largest province and the desert area is mostly home to Sunnis. The province has been a hotbed of Iraq's insurgency for years. Sunni militants aligned with terror groups such as al-Qaida often attack the local police and military, whom they see as traitors and supporters of the Shiite-led government.

Under a 2008 agreement, all American forces must leave Iraq by the end of this year, although U.S. and Iraqi officials have been discussing retaining a small U.S. military presence into 2012. There are currently about 43,000 troops still in the country.