UN Secretary-General Ban Ki-moon has made a surprise visit to the Libyan capital aiming to bolster talks between rival groups that have divided the North African nation with two separate parliaments and governments.

The UN chief arrived in Tripoli on Saturday and pressed Libyan politicians to pursue dialogue and restore stability to their crisis-ridden country.

The country cannot afford to be politically divided, it needs one parliament that represents all Libyans.

- Ban Ki-moon, UN Secretary General

Speaking to rival politicians, Ban said: "The country cannot afford to be politically divided, it needs one parliament that represents all Libyans."

Ban met with the deputy speaker and other lawmakers from the elected parliament, the House of Representatives, which has moved to the eastern city of Tobruk, as well as Misrata members of the assembly who have boycotted the sessions.

Libya has witnessed a spasm of violence since June, when militias mainly from the western city of Misrata and groups allied to Islamists swept through the capital, backing a government appointed by the country's previous parliament.

Libya's parliament, which was elected in June, is recognised by the international community but contested by militia controlling the capital Tripoli and by Islamists in the eastern city of Benghazi.

The majority faction in the legislature has been meeting in the far eastern town of Tobruk near the border with Egypt.

On Friday, the UN said fighting in Tripoli in the past three weeks had displaced at least 100,000 people, with another 150,000 fleeing the country, including many migrant workers.

"With fighting among rival armed groups intensifying in a number of areas of Libya, we are seeing growing displacement, now estimated at 287,000 people in 29 cities and towns countrywide," the UN refugee agency, UNHCR, said in a statement.

Last week, the UN Security Council warned of possible sanctions against those who reject peace in Libya.

The North African nation has been sliding into chaos since longtime leader Muammar Gaddafi was toppled in an uprising three years ago, with interim authorities confronted by powerful militias that fought to oust him.

Source: Al Jazeera and agencies