Independent projections on Monday gave President Milo Djukanovic's alliance, which aims to end Montenegro's partnership with much larger Serbia in the Yugoslav federation, just two seats more than its main rivals and failing to get an overall majority.
"I think now there are more chances to preserve the federal state," added Yugoslav Deputy Prime Minister Miroljub Labus, attending the annual meeting of the European Bank for Reconstruction and Development in London.
In Brussels, the European Commission urged Montenegro to begin talks swiftly with Belgrade aimed at preserving the federation.
"The European Union's message has been very clear and consistent refrain from any unilateral action. That remains our message," said spokesman Gunnar Wiegand.
But the commission, the EU's executive arm, added that the 15-nation bloc would respect any democratic decisions agreed by Montenegro and Serbia, the only republics left in Yugoslavia.
The Organization for Security and Cooperation in Europe (OSCE) said voting was carried out "generally in line with international commitments for democratic elections," though it cited some shortcomings that needed to be corrected.
Tiny Montenegro has long chafed at domination by much larger Serbia.
Serbia has 9 million people and Montenegro just 600,000. Djukanovic has insisted that Montenegro can therefore never be equal to Serbia in a joint state and that it can achieve democracy and prosperity quicker without its dominant partner.
Yugoslavia once included Croatia, Slovenia, Macedonia and Bosnia before those republics broke away in the early 1990s, precipitating a series of bloody ethnic wars.
Before Slobodan Milosevic's ouster as Yugoslav president in October, Montenegro's leadership had argued that the republic needed to escape his heavy-handed rule. Now that he's gone, the independence drive has continued despite opposition from the pro-democracy leadership in Serbia.
Even before the vote, the United States and its European allies were opposed to Montenegrin independence, viewing it as a potential source of new instability in the Balkans.
Supporters of the federation celebrated until the early hours of Monday, driving around rain-soaked streets of Podgorica honking horns, waving Yugoslav flags and giving three-fingered Serb salutes as sporadic celebratory gunfire rang out.
But Djukanovic made clear he was still committed to the independence course and would seek an alliance with like-minded parties in the republic.
"We will start as soon as tomorrow on making the necessary arrangement to create a government committed to an independent, democratic and pro-European Montenegro," he told a large crowd of supporters chanting his name at a post-election party.
But the partner he needs to form a government, the Liberal Alliance, wants independence quickly and is against any attempts at retaining even a loose alliance with much bigger Serbia.
Western diplomats fear immediate independence moves could exacerbate tensions and encourage other Balkan breakaway moves.
With 98.84 percent of votes counted, the republic's electoral commission said Djukanovic's alliance had won 42.05 percent, narrowly ahead of the anti-independence bloc, which had 40.67 percent of ballots cast.
The difference between the two groups was just below 5,000 votes. Close to 450,000 people were eligible to vote and the commission said turnout reached 80.84 percent. The Liberal Alliance Party got 7.65 percent of votes.
Montenegro's secession would mark the end of Yugoslavia, first formed as a kingdom for Serbs, Croats and Slovenes in 1918, at the end of World War I. In 1943, during World War II, the late communist leader Josip Broz Tito formed the second Yugoslavia of six republics.
© MMI Viacom Internet Services Inc. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press and Reuters Limited and contributed to this report