BENGHAZI, Libya — Two car bombs exploded as people left a mosque in a residential area of Benghazi on Tuesday night, killing 27 and wounding more than 30 in attacks timed to cause mass casualties among emergency workers, officials said.

Capt. Tarek Alkharraz, a spokesman for military and police forces in Benghazi, said the first explosion went off in the Salmani neighborhood around 8:20 p.m., and the second a half-hour later as residents and medics gathered to evacuate the wounded.

A local health official said at least 27 people were killed and 32 were wounded.

The United Nations condemned the attack, for which no group immediately claimed responsibility.

Libya fell into chaos after the ouster and killing of Muammar el-Qaddafi in 2011, and since 2014 it has been split between rival governments and parliaments based in the western and eastern regions, each backed by different militias and tribes.