WASHINGTON — Four American military personnel assigned to the United States Embassy in Tripoli, Libya, were detained Friday and then released after being held for hours by the country’s Interior Ministry, American officials said.

The four were believed to have been reviewing potential evacuation routes for diplomats when they were detained, according to the initial reports received by officials in Washington. The State Department spokeswoman, Jen Psaki, said they were working on “security preparedness efforts” when they were taken into custody. The area where they were said to have been detained is not far from the main road to the Tunisian border from Tripoli, the capital.

After running into a problem at a checkpoint — many of which are run by local militias — they were detained and later moved to the Ministry of the Interior, said administration officials who asked not to be identified because they were discussing internal reports.

Photographs of two American passports and embassy identity cards were later disseminated on Twitter. It was not known if the passports belonged to any of the four military personnel.