Insurgents dressed in military uniforms launched a coordinated attack on a government compound in the western city of Ramadi on Tuesday, but the assault was partly foiled by local police, who had taken over security of the compound from the Iraqi army four months ago.

Two police officers, one civilian and a leader of the Sons of Iraq, a Sunni counterinsurgency coalition, were killed by twin suicide bombs, said Brig. Mohammed Rashid, the police commander in Ramadi, capital of Anbar province.

Fifteen policemen were injured in an ensuing firefight with five gunmen who breached the perimeter of the compound after the explosions. Police shot and killed the gunmen. They also fatally shot a third would-be suicide bomber before he could trigger his device.

One suicide bomber detonated his explosives at the eastern gate of the compound about 12:45 p.m., and another blew up his car at the western gate. Police then cordoned off the compound, and gunfire could be heard inside.

The compound, about 60 miles west of Baghdad, houses the headquarters of the Anbar police department, government and counterterrorism bureau. It has been the site of seven insurgent assaults in the past two years.

Tuesday’s attack bears the fingerprints of al-Qaeda in Iraq, said Saadoun al-Shaalan, deputy chairman of the provincial council of Anbar, a majority-Sunni province that was once a stronghold of the insurgent group.

“This is solid evidence that al-Qaeda doesn’t represent the Sunni sect or the citizens of Anbar,” Shaalan said of the attack. “And it also gives you real evidence that we are on the right path” with local security.

Nevertheless, a new government compound is under construction in western Anbar, a location that might provide more of a buffer against attacks.

Among the dead Tuesday was Khalid al-Alwani, one of the leaders of the Sons of Iraq.

The coordinated attack was reminiscent of a more devastating raid in March on a provincial government headquarters in the northern city of Tikrit, where gunmen and suicide bombers in military garb killed more than 50 people.

The latest Anbar incident continues a string of bold insurgent attacks in the province this month. Last week, gunmen killed 22 Shiites from Karbala on a pilgrimage to a shrine in Damascus, Syria. The massacre, in a desert valley west of Ramadi, triggered a helicopter search by the Iraqi military that resulted in the arrests of 10 men, six of whom were released Saturday because of a lack of evidence and four of whom remain in custody in Anbar.

Lt. Gen. Farouk al-Araji, an adviser to Prime Minister Nouri al-Maliki, told reporters Sunday that the attack on the pilgrims was executed with precision by cooperating foreign groups. The suspects are Arabs from outside Iraq, he said.

Elsewhere Tuesday, three Iraqi policemen were killed by gunmen using silencer pistols at a checkpoint in the Shiite district of Shaab, in northern Baghdad, and a district police commander was injured by a bomb attached to his car in the city of Baqubah, about 35 miles northeast of the capital.

Iraqi government and religious leaders have said such sporadic attacks are designed to inflame sectarian violence as the Dec. 31 deadline for U.S. troop withdrawal approaches.

Mokhtar is a special correspondent. Zak reported from Baghdad. Special correspondent Aziz Alwan in Baghdad contributed to this report.