SKHIRAT, Morocco (Reuters) - Some Libyan warring factions signed an initial United Nations-sponsored agreement on Sunday to form a unity government and end fighting, but a key player from a parliament controlling the capital Tripoli stayed away.

Western officials say the U.N. talks are the only hope of halting fighting among factions allied to the oil producer's two governments and parliaments vying for power four years after the ousting of Muammar Gaddafi.

An armed alliance known as Libya Dawn took over Tripoli and declared its own government and parliament a year ago, driving out the internationally recognized premier and deepening anarchy in the North African country.

The United Nations, wrapping up months of negotiations, had invited the warring factions to the Moroccan coastal town of Skhirat to sign an initial power-sharing agreement.

"This agreement will bring a step, an important step in the road of peace in Libya," U.N. Special Envoy Bernardino Leon told the ceremony attended by Arab and Western diplomats.

"Let me enhance one message: The doors will remain open for those who have chosen not to be here," he added.

But while delegates from the elected parliament, the House of Representatives based in the east, signed the deal, the Tripoli-based parliament, the General National Congress (GNC), refused to attend.

"We are still in the dialogue, but we don't really understand why they are rushing to sign before all the parties agree," Mowafaq Hawas, a GNC representative in Morocco, told Reuters.

Some representatives from municipalities in Tripoli and the western city of Misrata allied to Libya Dawn signed the deal.

Under the plan, Libya will get a one-year government of national accord. A council of ministers headed by a prime minister and two deputies would have executive authority. The House of Representatives would be the legislative body, a plan meeting opposition from the GNC.

The factions have yet to agree on details.

Diplomats say both governments face pressure from hardliners who favor a military solution.

Islamic State militants have exploited the power struggle by increasing their presence in Libya as they did in Syria, Iraq and Egypt. The group has executed dozens of Christians and attacked embassies.

U.S. Special Envoy for Libya, Jonathan Winer, played down the absence of the GNC. "There are only four of the delegates who did not sign," he told Reuters. "There is an opportunity for those who have not yet initialed this agreement to come aboard."