MADRID - A strong showing Sunday by a pair of upstart parties in Spain's general election upended the country's traditional two-party system, with the ruling Popular Party winning the most votes but falling far short of a parliamentary majority and at risk of being booted from power.

Days or weeks of negotiations will be needed to determine who will govern Spain, with the new far-left Podemos and business-friendly Ciudadanos parties producing shockwaves because of strong support from voters weary of high unemployment, a seemingly endless string of official corruption cases, and disgust over the country's political status quo.

If forced out of government, Prime Minister Mariano Rajoy and his Popular Party would become the third European victims this year of a voter backlash against austerity - following elections in Greece and Portugal seen as ballot-box rebellions against unpopular tax hikes and spending cuts invoked during the eurozone's debt crisis.

In past Spanish elections, the Popular Party and the main opposition Socialists were the established powerhouses and only needed support from tiny parties to get a majority in parliament when they didn't win one from voters.

But Podemos came in a strong third place and Ciudadanos took fourth in their first election fielding national candidates - setting up a period of uncertainty as parties negotiate with each other to see which ones may be able to form a governing alliance.

"Spain is not going to be the same anymore and we are very happy," said a jubilant Pablo Iglesias, the pony-tailed leader of Podemos.

With 99.9 percent of the vote counted, the Popular Party won 123 seats in the 350-member lower house of Parliament - far below the 186-seat majority it won four years ago after beating the Socialists in a landslide.

The Socialist Party received 90 seats, while Podemos and allies won 69 and Ciudadanos got 40.

Analysts said the outcome will make it extremely difficult for the Popular Party to form a coalition or get voted into parliament as a minority government because it does not get enough seats by allying only with Ciudadanos, its closest possible ideological partner.

The Popular Party would also need support from parties that won 17 seats in the northeastern Catalonia region and are seeking independence from Spain or want more regional financial power and feel alienated by Rajoy's firm rejection of their causes.

Rajoy told cheering supporters shortly after midnight Monday that he would try to form a government but didn't provide any details of how he might accomplish that goal. "This party is still the No. 1 force in Spain," he declared.

But Socialist leader Pedro Sanchez said the result clearly shows "Spain wants a move to the left," adding that he and his party are ready for talks that could lead to a governing accord.

"It looks like a Socialist government," said Federico Santi, a London-based analyst with the Eurasia Group political risk consultancy. "Reaching a deal between the Socialists, Ciudadanos, and Podemos is not going to be straightforward. ... But if the alternative is leaving the country without a government, the pressure will be on the parties."