A soldier, two policemen and two students are among the dead.
After several hours of shooting outside the controversial Lal Masjid (Red Mosque) a ceasefire was negotiated.
Armed students at the mosque and religious schools linked to it have defied the authorities for months in a campaign for Islamic Sharia law.
The mosque and the two madrassas (religious schools) attached to it - one for men, the other for women - have been at the centre of a number of high-profile incidents.
These include the kidnapping of police and people the mosque's leaders say are involved in immoral activities such as prostitution.
The BBC's Syed Shoaib Hasan who is outside the mosque says the ceasefire was negotiated by a politician from the MMA, a coalition of Islamic parties.
Police and doctors say two policemen, one soldier, two students and a passer-by were killed. A cameraman filming the violence also died.
Other reports put the death toll at more than 10.
At the height of the violence, regular police and paramilitary units ringing the mosque compound were replaced by what appeared to be special forces, our correspondent says.
Ambulances and journalists were told to move further away from the scene.
Large groups of students - mostly armed with sticks and petrol bombs, but some with guns and wearing masks - have been patrolling around the mosque.
The first confirmed death on Tuesday - of a paramilitary soldier - was the first fatality in the prolonged stand-off between the authorities and the students.
A senior paramilitary official, Masha Allah, told reporters outside the Lal Masjid that the soldier had been "killed in the firing from inside the mosque".
Doctors at a nearby hospital later said two students had also succumbed to their gunshot injuries.
The students say scores of people from the mosque have been affected by the tear gas.
Doctors confirmed they were treating about 60 people suffering the effects of tear gas, the Associated Press news agency reported. Several students had bullet wounds, doctors said.
Critics have attacked the government for failing to enforce its authority in the capital.
President Musharraf has previously said security forces cannot raid the mosque for fear of reprisal suicide attacks.
BBC correspondents say it is thought the mosque has powerful friends in the security services, which has prevented the authorities from taking action.But the fact that people have now been killed in the stand-off suggests the situation may be turning against the mosque leaders, our correspondents say.