Former rebel gunmen freed Libya's prime minister on Thursday after holding him for several hours in reprisal for the capture by U.S. forces at the weekend of a Libyan Al-Qaida suspect in Tripoli.

"I am fine, thank God," Ali Zeidan tweeted after his release. "If the aim of the kidnapping operation was for me to present my resignation, then I won't resign. We are taking small steps, but in the right direction."

"The prime minister has been released," a government official confirmed. A security source also confirmed Zeidan was free.

A Reuters journalist outside the Interior Ministry building where the prime minister was held by militiamen linked to the government said people demanding his release had opened fire at one point. Zeidan was seized at dawn from a luxury hotel where he lives under tight security and was held for about six hours.

Two years after a revolution ended Muammar Gadhafi's 42-year rule, Libya is in turmoil, with its vulnerable central government and nascent armed forces struggling to contain rival tribal militias and Islamist militants who control parts of the country.

The militia, which had been hired by the government to provide security in Tripoli, said it "arrested" Zeidan after U.S. Secretary of State John Kerry said Libya had a role in the weekend capture in the city of Abu Anas al-Liby.

"His arrest comes after ... [Kerry] said the Libyan government was aware of the operation," a spokesman for the group, known as the Operations Room of Libya's Revolutionaries, told Reuters.

Before his release, an official in the Interior Ministry anti-crime department told the state news agency that Zeidan, a former diplomat and exile opposition activist against Gaddafi, was being held there and was being treated well.

The Libyan government in a statement confirmed the premier was taken at dawn to "an unknown place for unknown reasons."

The prime minister, who is in his early 60s, was taken from the Corinthia Hotel, where many diplomats and top government officials live. It is regarded as one of the most secure places in Tripoli.