Security forces in Libya have captured one of Egypt's most wanted jihadists during an operation in the eastern port city of Darnah.

Hisham al-Ashmawy, a former army officer, is accused of being behind several deadly attacks in Egypt and an attempt against a top state official.

He had a suicide vest strapped on, said the Libyan National Army, which controls much of eastern Libya.

Libya has been unstable since the fall of Muammar Gaddafi in 2011.

His 40-year rule ended when he was ousted and killed by rebels during the so-called Arab Spring protests.

The North African country is now mostly controlled by a UN-backed government based in the capital, Tripoli, and by the rival LNA, under military strongman Khalifa Haftar, whose forces hold sway in much of the eastern part of the country.

The LNA said in June that it had taken control of Darnah from jihadists though it was still facing some sporadic resistance.

"The terrorist Ashmawy was arrested in the Al-Maghar neighbourhood in the city of Darnah and was wearing an explosive vest but was unable to detonate it," the LNA said about the capture.

It said it would hand over the militant to Egyptian authorities after investigations, Reuters news agency reports.

Egypt has close relations with the LNA and has launched air strikes over Darnah, saying it was targeting jihadists linked to militant activity inside Egypt.

Egyptian officials say Ashmawy was behind the attempted assassination of then Interior Minister Mohamed Ibrahim in May 2013, and the killing of the country's top public prosecutor in a car bomb in 2015.

They say he headed the al-Qaeda-linked Ansar al-Islam militant group, after switching his allegiance away from the Islamic State group.

Ansar al-Islam claimed responsibility for an ambush that killed dozens of Egyptian policemen last year.