"People outside began running for cover and shouting, 'There are men with guns!' " said Abdul Qayyum, a neighborhood 9.
Once inside, the gunmen began firing wildly and hurling grenades, witnesses said. Two of the attackers detonated suicide vests.
"The bullets seemed to be coming from all sides," said worshiper Abdul Rauf. "Everyone was panicking, racing into bathrooms or up the stairs to find a place to hide. There were dead bodies and blood everywhere."
Two of the gunmen fired at police from a minaret. One later descended and detonated his suicide, said Khusro Pervez, Lahore's top administrative official.
After a three-hour standoff, police regained control of the mosque and arrested two of the militants.
In addition to the three attackers who blew themselves up, one was killed by security forces, said Shuja Khanzada, an advisor to Punjab provincial Chief Minister Shahbaz Sharif.