Unlock stock picks and a broker-level newsfeed that powers Wall Street.

UPDATE 7-Portugal's ruling Socialists win election but fall short of outright majority

* Socialists improve score but still need allies

* PM pledges to cut debt, but will need hard-left support

* Pro-environment party gets at least four seats

* Far-right party wins first seat since end of dictatorship (Adds far-right, analyst, details)

By Sergio Goncalves and Catarina Demony

LISBON, Oct 7 (Reuters) - Portugal's ruling Socialists won Sunday's parliamentary election but fell short of an outright majority, meaning Prime Minister Antonio Costa will need to negotiate a new deal with one or both of his far-left allies in the previous legislature.

A few weeks ago, opinion polls showed that Costa, with ratings boosted by a strong economy, was within reach of a full majority. But the gap narrowed, leaving his Socialist party (PS) stronger than in the 2015 election but still needing allies.

"It's clear from this election that the PS is reinforced and the allied parties consolidated their positions," Costa, smiling broadly, told supporters chanting: "Victory! Victory".

"Since we don't have a majority alone, we have to find solutions that guarantee stability for the next four years," he said.

Costa said voters liked the 2015 deal that saw the Left Bloc and the Communists unexpectedly back his Socialists to sideline the right, and that he wanted it to continue, adding that he also meant to negotiate with the upstart People-Animals-Nature (PAN) party.

With most of the votes counted, the Socialists led with 106 seats. That put them in first place, but with only four seats still not accounted for, they cannot reach the full majority of 116 seats in the 230-seat assembly.

The Socialists substantially increased their score from their 86 lawmakers in 2015.

Costa's minority government has received praise from Brussels and at home for combining fiscal discipline with measures to promote growth after recession and the austerity of Portugal's 2010-14 debt crisis.

He told supporters he would continue to cut the budget deficit and the debt. But that could be complicated by his potential allies' demands.

"These negotiations could be more complex than four years ago when the pact on the left was cemented by their common goal to unseat the right," said political scientist Antonio Costa Pinto.

"Now the left as a whole has been reinforced. ... Obviously they will test the budgetary limits and the economic projections for the next few years," Costa Pinto said, expecting the negotiations to take a few weeks, now with more participants.

President Marcelo Rebelo de Souza is likely to demand assurances from the parties that the solution would be a lasting one.