Conservative Prime Minister Mark Rutte claimed victory in The Hague Wednesday night, amid wild cheering and whistling from his jubilant supporters.
"This night is a night for the Netherlands -- after Brexit, after the American elections -- where we said stop it, stop it to the wrong kind of populism," he said.
Turnout was 81%, according to state broadcaster NOS, the highest in three decades. Long lines formed at some polling stations as voters turned out in droves.
The election was widely seen as a test of populist right-wing sentiment in Europe, ahead of the French presidential vote in April and the German national election in September.
With 94% of the votes counted, Rutte's Party for Freedom and Democracy, the VVD, was projected to win 33 seats in the national parliament out of a total of 150. Wilders' Freedom Party, the PVV, was on course to win 20 seats, only one more than the mainstream Christian Democratic Appeal and D66 parties.
Rutte's party, which lurched to the right in response to the populist wave, won eight fewer seats than in 2012, but the VVD's success staving off the challenge from Wilders was celebrated as a victory.
Wilders, who is staunchly against mass immigration and the European Union, was defiant, claiming he was "part of the winners."
"Rutte uses terrifying words when he says that the elections have put a halt to the wrong type of populist ... (He) has not got rid of me yet," he said.
Relief in Europe
During his speech to supporters, Rutte said many European leaders had already called to congratulate him on his victory.
French President Francois Hollande called it a "clear victory against extremism."
"The values of openness, respect for others, and a faith in Europe's future are the only true response to the nationalist impulses and isolationism that are shaking the world," he said.
Germany's foreign ministry said: "Large majority of Dutch voters have rejected anti-European policies... That's good news. We need you for a strong Europe!"
Italy's Foreign Minister Paolo Gentilioni tweeted that the "anti-EU right" had lost in the Netherlands.
"All together for change and revive the (European) Union."
However, Nicolas Bay, Secretary General of France's far-right Front National, congratulated Wilders, tweeting that his "party progresses, it's a real success." The Front National's presidential candidate, Marine Le Pen, is polling strongly ahead of France's first round of voting on April 23.
Wilders: 'European spring' will come
Even though his party won a handful more seats than in 2012, the result is a blow for Wilders, who had been leading polls for much of 2016.
He rode the same wave of anti-establishment fervor
that saw UK voters opt to leave the European Union, and the election of US President Donald Trump.
Wilders ran on a "de-Islamification" platform, calling for Islamic schools to be closed and the Quran and burqa to be banned.
Wilders said he was still expecting to see a "European spring" for his supporters.
"I think our influence has been enormous ... Our patriotic spring will continue, will really start. And if they need me or if they need the PVV for talks (on a coalition) then I am happy to take part," he said.
"If not, then they haven't seen the back of me yet."
Netherlands 'deeply divided'
Andre Krouwel, political scientist at the Free University Amsterdam, and owner of election website Kieskompas, said the only conclusion from the election result was that the Dutch were "deeply divided."
"It's very difficult to interpret this election result other than this is a very polarized result, people have abandoned the centrist parties but they have also abandoned the left-wing project ... the left together has 37 seats in the 150-seat parliament," he said.
Krouwel also said Wilders, despite his slight gain of seats, now faced being almost powerless in the new political environment.
"The very vocal minority ... dominated the elections and everybody focused on Wilders. But in the end he's totally impotent to do anything. Nobody wants to coalition with him," he said.
The final days of the election were dominated by a diplomatic row with Turkey over the Dutch government's refusal to allow Turkish ministers to address political rallies in the Netherlands.
Krouwel said the war of words between Turkish President Recep Tayyip Erdogan
and the Dutch government in the past month may have boosted support for Rutte.
Coalition talks to begin
More than 28 parties took part in the election and, with none winning a majority, a coalition is inevitable.
Final results may not be known before Friday, the head of the ANP election service Mark Westerhoff said. There are 22 of 388 municipalities left to report.
When the results are complete, Rutte will begin negotiations to form a government. Potential partners include the GroenLinks (Green left) Party and the Socialist Party, which were poised to win 14 seats each.
Support for the PVDA (Labour) party, which had been Rutte's partner in government, plunged from 38 seats to nine.
In his victory speech, Rutte struck a conciliatory note.
"Now in the next couple of weeks and months it is important to unite the country, we have to make sure that we form a stable government so that the country for the next four years can be governed wisely," he said.