Murad Sezer, Associated Press
A Turkish flag waves near the U.S. consulate in Istanbul, Turkey, after armed men attacked Wednesday. Three policemen and three assailants died.

ISTANBUL, Turkey — Gunmen believed inspired by al-Qaida stormed a guard post at the U.S. consulate Wednesday, touching off a firefight that killed three police and three assailants in the latest sign of Turkey's difficulty in clamping down on homegrown militants.

The bearded gunmen emerged from a car and shot a traffic officer dead, then swarmed the guard quarters at the entrance to the consulate, where two policemen were killed, according to security video. Officers fired back, killing three of the assailants — all Turks — as bystanders fled for cover. At least one attacker escaped in the car.

An officer told The Associated Press that police suspected the armed men were linked to al-Qaida even though the assault did not match the terror group's usual hallmarks, such as coordinated attacks by suicide bombers that cause mass casualties.

The suspects may have been inspired by al-Qaida ideology without the capability to carry out more sophisticated attack, said the officer, who spoke on condition of anonymity because he was not authorized to speak to reporters.

No staff at the consulate, a relatively new building perched on a hill and surrounded by high walls, were hurt, U.S. Ambassador Ross Wilson said.

The attack sent people who had been waiting for visas running into shops and cafes across from the consulate, an eyewitness said. After the attack, bullet holes dotted three sides of the concrete-brick guard post.

Wilson and Istanbul's governor branded the assault a terrorist attack. Security around all U.S. diplomatic missions in Turkey was immediately increased, and the consulate canceled visa interviews for Thursday.

Turkish authorities have been increasingly targeting suspected Islamic militants since al-Qaida-linked suicide bombers killed 58 people in 2003 by targeting two synagogues, the British consulate and a British bank in Istanbul.

Turkey has also been cracking down on both ultranationalists who have attacked Christians and on Kurdish rebels, two groups it deems a threat to the country's security.

"Turkey is a fertile ground which is nourishing militants from almost every ideology — from radical Islamic ones to leftist and ultranationalist ones," said Nihat Ali Ozcan of the Economic Policy Research Institute in Ankara.

"It is difficult to contain them, and it is even more difficult to prevent terrorist attacks," he added.

The attack also comes amid heightened tensions between the Islamic-oriented Turkish government and secular circles backed by the military, with the ruling party facing a legal effort to close it down. The United States has expressed support for government-led democratic reforms in Turkey, but has been careful not to take a side in the dispute.

NTV television and Dogan news agency identified the attackers as Erkan Kargin, 26, and Raif Topcil, 20, from the southeastern city of Bitlis and Bulent Cinar, 23, from the eastern city of Igdir. Police would not confirm their identities, but Interior Minister Besir Atalay said two of the assailants had criminal records.

Turgay Akdemir, who owns a small business across from the consulate, told the AP he saw three men with beards, armed with pistols and at least one shotgun, emerge from a gray car and shoot at police.

One approached the guard post, which had a door slightly open, and shot at the three policemen inside, Akdemir said. He said two of the assailants were killed by a traffic officer who had been shot in the arm, separate from the traffic officer who was killed.

The eyewitness said the car then turned and sped away. "I wanted to scream, but there was a knot in my throat," he said.

The private Dogan news agency said security camera footage from the site showed four armed, bearded men emerging from the car. U.S. security officers, who are not allowed to engage in armed action on Turkish soil, ducked inside the compound. In Turkey, secular men are rarely seen with beards.

"There is no doubt that this is a terrorist attack," Istanbul Gov. Muammer Guler told reporters at the scene, calling the three slain policemen martyrs. Two other people were injured, he said — a truck driver and the traffic policeman who fired back after he was hit.

U.S. Secretary of State Condoleezza Rice, traveling to Tblisi, Georgia, said she did not know whether the consulate in Istanbul was the intended target or who was responsible.

"The Turkish authorities reacted quickly and we appreciate that," she said. "Obviously first of all the United States deeply regrets the loss of life and condolences go out to the families of those who were killed."

The consulate occupies an imposing structure on a hill in Istinye, a densely residential neighborhood along the Bosporus on the European side of Istanbul.

Still, a reporter for The Associated Press was able to drive unimpeded last week past a consulate entrance for the public and park nearby on a residential street. The area directly in front of the entrance was kept clear of vehicles and several Turkish guards stood outside, but weapons were not on display.

The U.S. ambassador praised the quick action of the Turkish police and stressed that the United States and Turkey would keep working together against terrorism.

"It is, of course, inappropriate now to speculate on who may have done this or why. It is an obvious act of terrorism," Wilson said. "Our countries will stand together and confront this, as we have in the past."