KHARTOUM, July 6 (Reuters) - Sudanese police fired teargas at worshippers trying to leave a mosque to demonstrate after Friday prayers, witnesses said, as the government attempts to quell protests against austerity measures and calls for greater freedoms.

The past three weeks have seen small-scale protests across Sudan calling for the government of President Omar Hassan al-Bashir, in power for 23 years, to resign.

The demonstrations have yet to attract the large numbers seen in Egypt, Libya and Yemen, but they pose another challenge to a government trying to deal with multiple rebellions and an economic crisis.

Online activists, some inspired by the Arab Spring uprisings last year, have been using social media to call for larger demonstrations, but Sudanese police and security forces have routinely and swiftly crushed any sign of dissent.

Hundreds of people have been detained and one journalist has been deported, Sudanese activists say.

On Friday, hundreds of protesters left the Imam Abulrahman mosque in the Omdurman suburb of Khartoum, only to be driven back inside by teargas.

“They had barely begun chanting for a minute. From the moment they left the mosque, the police fired teargas,” one witness said. “They have now escaped inside and the police are surrounding the mosque’s courtyard.”

An activist who said she was at the mosque told Reuters police fired teargas every time protesters chanted “Freedom. Peace. Justice. Revolution is the choice of the people”.

“There was panic. Some people were choking and gasping,” the activist, who declined to be named for security reasons, said by phone.

“There are piles of rocks and sticks inside the mosque’s yard for the protesters to protect themselves. Young men are guarding the main doors of the mosque while police have blocked some entrances on the street.”

FEAR OF ARREST

Police spokesman As-Sir Ahmed Omar said there had been a “limited protest which police contained without any losses”.

The mosque, one of the country’s largest and most famous, has been a frequent flashpoint for protests. It is associated with the opposition Umma party, which along with other opposition parties backed demonstrations earlier this week, but has so far refrained from bringing out its supporters in large numbers.

By nightfall, about 100 people were still inside the mosque, another activist told Reuters by telephone.

“Police are standing about two to three blocks away from the mosque. People are worried if they leave a mosque they’ll be arrested,” he said.

“They’re not arresting everyone. If you’re 40 years old and in a jellabiya (traditional dress) then you’re fine,” he said.

Protests that started on university campuses soon spread to other parts of the capital and beyond, but have rarely mustered more than a few hundred people.

“The protests are clearly only beginning, but they will not become a serious challenge to the regime unless the opposition becomes more organised and disciplined,” EJ Hogendoorn, Horn of Africa project director at the International Crisis Group, told Reuters.

At the Sayyid Ali mosque in the Khartoum suburb of Bahri, protesters were also forced back inside after police fired teargas as soon as they left to demonstrate.

Sudan has announced austerity measures, including scaling back fuel subsidies, to help keep the economy afloat after its oil revenues collapsed when South Sudan declared independence last year, taking three quarters of the oil output with it.

The government of Sudan has dismissed the protesters as a few agitators acting on behalf of a Zionist-American plot. Security forces have so far refrained from using deadly force to quell the protests.

“I suspect the authorities know that the use of deadly force could backfire and spur more protests and possibly lead to wider violent conflict. They will do everything they can to avoid alienating people and prevent the protests from growing, Hogendoorn said.

Sudan witnessed popular uprisings in 1964 and 1985 which toppled military rulers on both occasions. (Editing by Janet Lawrence)