Libyan Prime Minister Ali Zeidan, center, arriving at government headquarters in Tripoli on Thursday shortly after he was freed. Mahmud Turkia/AFP/Getty Images

Libya's state news agency said Prime Minister Ali Zeidan had been freed after being captured Thursday and briefly detained, reportedly by government-aligned rebel groups. It is not clear if he was released willingly by his captors or if security forces intervened.

The government earlier said the prime minister had been kidnapped from a Tripoli hotel by armed men and taken to an unknown location. But hours later an Interior Ministry spokesman said Zeidan was being held at the ministry’s anti-crime department.

Zeidan returned to his office after he had been seized and held by former rebel militiamen for about six hours.

"The elected government cannot be toppled, unless by the vote of the people," Nuri Ali Abu Sahmain, president of Libya's General National Congress, the country’s legislative body, said at a news conference Thursday. "We will continue to address such incidents in a legal, lawful manner."

The chaotic situation appears to reflect the weakness of Libya's government, which is virtually held hostage by rival militias. Some of the groups were angered when the United States snatched an alleged Al-Qaeda member from Tripoli on Saturday, and have accused the government of allowing the raid.

Abdel Bari Atwan, the editor-in-chief of the London-based Al-Quds al-Arabi newspaper, told Al Jazeera Thursday that Libya is in a state of "anarchy."

"To reach this level and abduct a prime minister, this is actually a huge embarrassment for the Libyan government," he said.

Early reports of Zeidan's seizure depicted it in various ways, as either an abduction or an arrest — a sign of Libya’s chaos.

Abdel-Moneim al-Hour, an official with the Anti-Crime Committee, told The Associated Press that Zeidan had been "arrested" on accusations of corruption and harming state security.

A former rebel group, the Libyan Revolutionary Operations Chamber, said on its Facebook page that it had "arrested" Zeidan after the government allowed the United States to capture Al-Qaeda suspect Nazih Abdul-Hamed al-Ruqai, known by his alias Anas al-Liby, in Tripoli last weekend.

The group said Zeidan was "arrested under the Libyan penal code ... on the instructions of the public prosecutor."

However, the public prosecutor's office said it had issued no warrant for Zeidan's arrest.

The prime minister had suggested on Sunday that his government had not been informed of the planned U.S. raid in Tripoli, saying his administration had contacted U.S. authorities "to ask them to provide an explanation."

Al-Liby was wanted by the United States for his alleged role in the 1998 bombings of two U.S. embassies in East Africa.

With the country's security forces in disarray, many are enlisted to serve in state security agencies. However, their loyalty often goes more to their own commanders than to government officials, whom they have often threatened or intimidated. The militias are rooted in brigades that overthrew former Libyan leader Muammar Gaddafi in 2011.

Al Jazeera and wire services