A bomb has rocked the playground of a primary school in Benghazi during break time, wounding 12 children, hours after gunmen had rampaged through the streets of Libya's restive second city.

Witnesses said the bomb was thrown over the school wall while the children were playing.

Fadia al-Barghathi, spokesperson for Benghazi's main Galaa hospital, told the AP news agency that it was a student that had thrown the device.

Six children suffering "light to moderate" injuries were admitted to the city's Al-Jala hospital, Barghathi said.

Medics said two of the injured children were in serious condition.

Weapons are widespread in Libya in the wake of its 2011 civil war.

Benghazi, cradle of the 2011 NATO-backed uprising that toppled Muammar Gaddafi, has seen near-daily attacks on security and other targets in recent months as the weak central government has tried to rein in former rebel brigades turned armed groups.

Another medical official said six other children, two in serious condition, were taken to Benghazi medical centre.

A security official described the force of the explosion as "weak" and said a hunt was underway for whoever was behind the attack, for which no one immediately claimed responsibility.

"Witnesses saw an individual throw an explosive device over the school wall during recess," the official told the AFP news agency, speaking on condition of anonymity.

Special forces attacked

The attack came hours after a patrol of Libya's Al-Saiqa special forces unit was attacked by unknown gunmen during the night in the centre of Benghazi, causing no injuries.

A security official said the assailants had then attacked a sit-in being staged by a group of anti-government protesters, torching their tents and cars.

The gunmen later attacked a checkpoint at Al-Jala hospital, sparking a firefight that left no injuries.

Three members of the special forces were killed in Benghazi last week in clashes with armed groups made up of former rebels.

Armed groups have also attacked foreign missions in Benghazi, including a September 2012 assault on the US consulate that killed the ambassador and three other Americans.

Eastern Libya has become a stronghold of militias, with authorities avoiding a full-blown confrontation with the heavily-armed groups pending the formation of a regular army and police force