TRIPOLI (Reuters) - Gunmen killed a lawyer and prominent Libyan political activist as well as two military officials in separate attacks in the eastern city of Benghazi on Friday, security officials said.

Lawyer Abdelsalam al-Mosmary was shot after he left a mosque to make his way home.

"He was coming out of Friday prayers when he was shot," Benghazi security spokesman Mohammed al-Hijazy said. "It seems it may have been the work of a sniper because he was shot in the heart."

It appeared to be the first attack against an activist in the city although security forces have been targeted frequently.

"This has never happened before, this a first in Benghazi," said Kais al-Bakshishi, a political activist.

In regular television appearances, Mosmary criticized the presence of armed militias on Libya's streets and expressed his opposition to the Muslim Brotherhood.

A large crowd later gathered in downtown Benghazi to protest the killing.

Two military officials were also killed in the city in separate incidents later on Friday.

Unknown assailants shot air force Major Colonel Salem al-Sarah as he was leaving a mosque after evening prayers, army chief of staff spokesman Ali Sheikhi said.

Younis al-Zway, an army colonel from the eastern town of Jalu who was on a mission in Benghazi, was shot while driving. "He lost control of the vehicle, it flipped and he was killed," Benghazi senior police official Younis Ahmed told Reuters.

Benghazi is where the uprising against Muammar Gaddafi began in February 2011 but is now a hot spot for violence, with numerous attacks on security forces.

Libya's weak central government is struggling to assert its authority over armed groups that helped topple Gaddafi but have yet to lay down their weapons. Islamist militants have also come to the fore.

Last September, the U.S. ambassador and three other Americans were killed in an attack on the U.S. mission in Benghazi.

(Reporting by Ghaith Shennib and Feras Bosalum; Writing by Marie-Louise Gumuchian; Editing by Doina Chiacu)