Two hours after the attack began, occasional gunshots were still being heard from inside the heavily fortified area in the garrison city of Rawalpindi just a few miles from the capital. Reporters were kept away from the scene.
Three helicopters hovered overhead while trucks carrying commando teams and ambulances raced through the cordoned-off area as soldiers kept onlookers and traffic away.
The attack, the third to target Rawalpindi in nearly two months, began when several gunmen staged an explosion to break through a checkpoint close to the mosque, which was popular with army officers, said Yasir Nawaz, a police official at the scene.
He said the installation included an army parade ground as well as the mosque, which was often used by military officers.
Two of the assailants were able to enter the mosque and sprayed the congregation with gunfire and grenades, said military spokesman Maj. Gen. Athar Abbas. He said there were other attackers, but provided no details about them.
An intelligence official said 35 people were killed, their bodies taken to two hospitals close to the scene. Seventy others were wounded.
On Nov. 2, a team of militants attacked the army headquarters and held dozens hostage in a 22-hour standoff that left nine militants and 14 other people dead.
Violence in nuclear-armed Pakistan has escalated since the army launched an offensive in mid-October against Taliban militants in the northwestern tribal area of South Waziristan near the Afghan border. Soldiers have pushed deep into what was a militant stronghold, but many insurgents appear to have fled.