PARIS — The leaders of rival Libyan factions agreed Tuesday to work together on a legal framework for holding presidential and parliamentary elections this December in a deal being pushed by France’s president to bring stability to Libya and stem the flow of migrants to Europe from its shores.

It was latest of numerous international efforts to find a political solution to the chaos plaguing Libya since the ouster of Col. Muammar el-Qaddafi in 2011. But analysts said the election timetable was extremely optimistic and that the agreement, as with previous efforts, risked being undermined by opposition from armed groups on the ground.

Under the terms of the agreement, the Libyan leaders will set election rules by mid-September, hold the vote on Dec. 10 and ensure that voters and candidates will be safe. The leaders also agreed to eventually streamline their parallel government structures and merge their armed forces and other security entities.

Power in Libya is divided between two rival governments, in the east and west of the country, and a plethora of armed groups that pledge allegiance to either administration, or none.