At least 13 people have been killed in a suspected suicide bombing near Pakistan's Red Mosque, following clashes between Islamists and police.
"Most of the dead were policemen," a security official said. More than 50 people were injured.
Torn police uniforms lay about the scene in Islamabad while blood stained the streets, a BBC correspondent said.
The mosque was the scene of a bloody siege that ended earlier in July with the deaths of more than 100 people.
A protest grew on Friday as students demanded the return of the mosque's surviving pro-Taleban cleric, Abdul Aziz, who is in detention.
Security forces initially stood by as the protesters emerged from the mosque chanting "[President Pervez] Musharraf is a dog!", and calling for an Islamic revolution.
But as angry demonstrators started hurling stones at police, officers in full riot gear were deployed and tear gas was fired.
The protesters daubed red paint over the mosque, which had been repainted in pale colours by the authorities after the end of the siege.
They wrote "Red Mosque" in large Urdu script on the dome of the building. They also raised a black flag with two crossed swords - meant to symbolise jihad, or holy war.
Earlier protesters had prevented a government-appointed cleric from leading Friday prayers at what was supposed to be the peaceful re-opening of the mosque.
"I was told everything would be peaceful. I was never interested in taking up this job and after today I will never do it," Mohammad Ashfaq told AFP news agency as he left the mosque with a police escort.
The explosion took place in a restaurant outside the mosque soon after the protests were subdued by police, said the BBC's Dan Isaacs, who was only a short distance away.
It appeared to be targeted at the police cordon arranged round the mosque, where dozens of officers were lined up, he said.
A security official told the AFP news agency the bomb was set off by a suicide attacker.
"A man detonated explosives strapped to his body among two rows of Punjab police constabulary members who were there on duty because of the unrest at the Red Mosque," he said.
Officials said seven police officers were among the dead.
Centre of radicalism
Such a high-profile attack in the heart of the Pakistani capital will be extremely worrying for Pakistan's President Pervez Musharraf, who is under increasing political pressure and facing rising violence by militants, our correspondent says.
Less than three weeks ago, troops stormed the mosque after its clerics and students waged an increasingly aggressive campaign to enforce strict Sharia law in Islamabad.
The mosque had become a centre of radical Islamic learning and housed several thousand male and female students in adjacent seminaries.
Protesters daubed the mosque with graffiti
The chief of Dyala prison in Rawalpindi told Pakistan's Supreme Court that 567 of the 620 students detained during the siege and 36-hour battle had been freed. Of those still being held, three are women.
More than 100 people were killed in the siege, including 11 soldiers and an as yet unknown number of militants and others inside the mosque.
The attack on the mosque was the fiercest battle fought by security forces in mainland Pakistan since President Musharraf vowed to dismantle the militant jihadi network in the country in the aftermath of the 11 September 2001 attacks on the US.
More than 180 people have been killed in militant attacks in the past few weeks.
Also on Friday, a government spokesman in Baluchistan province was shot dead by gunmen, though their motivation was unknown.