A doctor at the mosque said 10 people were killed.
In a phone interview with state TV, Gadhafi accused al-Qaeda leader Osama bin Laden of being behind the uprising in Libya. The Libyan leader said the more than week-long revolt has been carried out by young men hopped up on hallucinogenic pills given to them "in their coffee with milk, like Nescafe."
"Shame on you, people of Zawiya, control your children," he said. "What do you have to do with bin Laden, people of Zawiya? They are exploiting young people ... I insist it is bin Laden."
President Barack Obama has told his administration to look at possible sanctions against the country, including freezing of assets and banning travel to the U.S. by Libyan officials.
"The suffering and bloodshed is outrageous, and it is unacceptable," Obama said on Wednesday during a news conference.
In the latest blow to the Libyan leader, a cousin who is one of his closest aides, Ahmed Gadhaf al-Dam, announced that he has defected to Egypt in protest against the regime's bloody crackdown against the uprising, denouncing what he called "grave violations to human rights and human and international laws."
After Thursday's assault, thousands massed in Zawiya's main Martyrs Square by the mosque, shouting "leave, leave," in reference to Gadhafi, the witness said. "People came to send a clear message: We are not afraid of death or your bullets," he said.
Gadhafi's crackdown has so far helped him maintain control of Tripoli, a city that holds about a third of Libya's 6 million population.
But the uprising has divided the country and threatened to push it toward civil war.
Meantime, hundreds of Americans will have to wait until at least Friday before getting out of Libya. A ferry leaving Tripoli to go to Malta is being delayed by bad weather.
The boat, loaded with Americans, was supposed to ship out on Wednesday but remained docked in the capital city.
The Associated Press contributed to this report.