Spain's main political parties outlined conflicting positions on how to form a viable government in the wake of an inconclusive election, suggesting the negotiations will be complex and time-consuming.

Socialist leader Pedro Sanchez, speaking to the media after meeting Prime Minister Mariano Rajoy, said he would reject any pact that led to a new government with Rajoy or his People's Party (PP), dashing hopes of a grand coalition of the mainstream left and right.

On Sunday, Rajoy's centre-right PP won the most votes but fell far short of a parliamentary majority, while the Socialists came second. Both lost significant ground to the relatively new liberal Ciudadanos and left-wing Podemos parties.

Without the backing of the Socialists, or at least their implicit support via abstentions, it would be impossible for the PP to form a government with a majority in parliament.

Other combinations are possible but they would require at least three parties reaching an accord.

"We say 'no' to Rajoy and his policies," Sanchez told a news conference after the meeting.

"The Socialists will work so that there is a new government, a government of change, with progressive ideas and capacity for dialogue," he said.

But he added that he would do everything he could to avoid fresh elections and that he would back Rajoy on issues such as terrorism or Spanish unity against the risk of seeing the northeastern region of Catalonia declaring independence.

Sources said the two did not discuss a pact in detail as the latter made clear at the start that he would not back the PP and that his party would instead seek backing from other groups to form a majority.

Rajoy, who was given the first chance to form a new government, is now set to meet Ciudadanos' Albert Rivera and Podemos' Pablo Iglesias next Monday.