The gun battle started when four insurgents in a taxi - a driver and three others disguised in women's all-covering robes - tried to cross through a checkpoint into Makka on Thursday evening, Brigadier-General Mansur al-Turki, an Interior Ministry spokesman, said.
When the group was stopped, they tried to flee and police captured the driver. But the three other anti-government fighters fled, with police in pursuit, al-Turki told the state-run television station Al-Ekhbariya.
Several security officials in Makka said the three fled into the neighbourhood of Umm al-Jud - which like much of Makka is built on hills - and took shelter in houses.
After several hours of fighting, two of the insurgents were killed and a third wounded and captured, the officials said.
Al-Ekhbariya showed footage of police with automatic rifles keeping back civilians in what appeared to be a residential neighbourhood.
The kingdom has cracked down
on al-Qaida since 2003
Two police officers were killed in the battle and a number of them wounded, while 15 police and civilian cars in the area were destroyed, the officials said.
Al-Turki confirmed the fighting had ended but refused to give any details.
The attack came about two hours after polls closed in Makka, where voters were participating in the third and final round of nationwide municipal elections.
Saudi Arabia has waged a crackdown against al-Qaida and other insurgents since 2003, after a series of deadly bombings. Its security forces have killed or captured 23 of the insurgents on the most-wanted list.
In the first week of April, security forces waged their biggest gun battle to date with insurgents, fighting a band of them for three days in the northwestern desert town of al-Rass.