BARCELONA, Nov 27 (Reuters) - Arab states and the European Union agreed at a meeting in Spain on Monday that a two-state solution was the answer to the Palestinian-Israeli conflict, with EU foreign affairs chief Josep Borrell saying the Palestinian Authority should rule Gaza.

Borrell said all EU members attending the meeting of Mediterranean nations in Barcelona and almost all attendees had agreed on the need for a two-state solution.

The Palestinian Authority must hold elections as soon as possible to gain further legitimacy and improve its functioning, as the only "viable solution" to the future leadership of Gaza, currently run by Hamas Islamists, he said.

"I believe is the only viable solution, but it will be viable if the international community backs it. Otherwise, we will see a power vacuum that will be fertile ground for all sorts of violent organisations," Borrell said at a press conference.

An initial four-day truce has been extended by two days, mediator Qatar said, in the first halt in fighting in the seven weeks since Hamas attacked Israel, killing 1,200 people and taking about 240 hostages into Gaza, according to Israeli tallies.

In response to that attack, Israel bombarded the enclave and mounted a ground offensive in the north. Some 14,800 Palestinians have been killed, Gaza health authorities say, and hundreds of thousands displaced.

Jordanian Foreign Minister Ayman Safadi said any talk of administration of Gaza after the conflict should focus on the West Bank and Gaza as one entity and that the Palestinian people should decide who rules them.

A two-state solution envisages a state for the Palestinians in the West Bank and Gaza Strip alongside Israel.

Palestinian Foreign Minister Riyad al-Maliki said the Palestinian Authority, which lost control of the Gaza Strip in a 2007 power struggle with Hamas, had no need to return to Gaza, adding: "We have been there all the time, we have 60,000 public workers there."

They were speaking at the conclusion of a meeting of the Forum for the Union of the Mediterranean in Barcelona, a 43-member grouping of European, North African and Middle Eastern countries. Israel did not attend the summit.

Saudi Foreign Minister Prince Faisal bin Farhan spoke as a representative of a group of ministers from the Arab League and the Organisation of Islamic Cooperation.

"We delivered our message, it's important that we have a ceasefire immediately, that we build on the current truce that is in place," he told reporters after the conference ended.

German Foreign Minister Annalena Baerbock said the absence of Israel due to apparent concern over "one-sided hostility" underscored "deep rifts".

"That is precisely why I am here today, even though these meetings were not previously given a high profile by Germany. Precisely because the rifts are getting deeper, we have to sit together, we have to talk and hear each other out," she said.