With nearly all the votes counted, the National Party took 46 percent of the vote, beating back a late surge by the center-left Labour Party, which received 35.8 percent, according to the Electoral Commission. Smaller parties took the rest.
Late Saturday night, Prime Minister Bill English delivered a victory speech in Auckland, New Zealand’s largest city, but his main challenger, the Labour Party leader Jacinda Ardern, did not immediately concede defeat.
Mr. English, a former finance minister, took the reins in December after his predecessor, John Key, unexpectedly resigned to spend more time with his family. During the campaign, Mr. English emphasized the party’s stewardship of the economy, which has recovered strongly from the financial crisis that was underway when the National Party swept to power in 2008.
Mr. English, who had failed in a previous bid to become prime minister in 2002, when he was National’s leader, so the party’s first-place finish on Saturday was something of a vindication.
Ms. Ardern took control of the Labour Party in July after its leader, Andrew Little, quit amid dismal poll numbers. She enjoyed a wave of attention for her charisma, her youth (she is 37), and for condemning a television commentator’s question about whether employers have a right to know whether a woman plans to become a parent.
During the campaign, she emphasized issues including child poverty, environmental management and housing affordability.
In the end, however, her efforts appeared to have fallen short.
Neither of the main parties won a majority of the 120-seat Parliament, which means that National, with 58 seats, and Labour, with 45, will now try to court minor parties to form a coalition — a process that could take days or even weeks.
Given its advantage, National is more likely to succeed, but to do so, it will need support from Winston Peters, a populist whose right-leaning New Zealand First party won nine seats.
Mr. Peters, 72, who is poised to act as kingmaker, did not tip his hand on Saturday, boarding a ferry to go home as reporters peppered him with questions. He said he would reach a decision by Oct. 12.
(Although Mr. Peters leans to the right, he is unpredictable, and he could conceivably ally with Labour and the Green Party, which won 7 seats. Together, the three parties would have 61 votes, a knife-edge majority. That scenario is considered unlikely but not out of the realm of possibility.)
Amid blue balloons and triumphant applause, Mr. English, 55, told supporters at Sky City Casino in Auckland, “We gave it everything, and we got better and better.”
Ms. Ardern, despite the setback, remains a fresh face in New Zealand’s male-dominated politics, and she is expected to remain an electoral force. She helped revitalize Labour’s popularity and strongly improved the prospects for a party that in the 2014 election won just 25 percent of the vote.
Ms. Ardern reminded supporters that she had once called the Labour leader’s position “the worst job in politics,” adding that she had now changed her mind. She said that the party and its supporters had given it “their all” and that, while she had called Mr. English to acknowledge that National had won the most votes, she was not ready to admit defeat.
The campaign was raucous, at least by the standards of New Zealand, a prosperous member of the Commonwealth that has largely been spared the divisive debate over migration that has roiled its larger neighbor, Australia.
The resignations of Mr. Key and of Mr. Little put new leaders in charge of the two biggest parties.
Then in August, a leader of the Green Party, Metiria Turei, resigned her post because of fallout from revelations that she had lied about her living situation in the 1990s, when she was a single mother, to receive welfare benefits.
The same month, Peter Dunne, the leader of United Future, a centrist party, said he would step down after the election, when it became clear that he could not retain the seat that had kept him in Parliament for 33 years.
Adding more uncertainty to the result is a likely high number of “special votes” — ballots cast by New Zealanders living overseas and by people registering to vote on the same day they cast their ballot. The count from those votes is expected by Oct. 7.
In the 2014 election, 12.5 percent of the ballots cast were special votes, and they tend to trend leftward. National lost one seat, and the Greens picked up one, as a result of the special-vote tally that year.
A major upset in Saturday’s results was the vanquishing of the Maori Party, a group which grew out of protest action about indigenous rights to New Zealand’s foreshore and seabed.
Formed in 2004, the party won two seats at the 2014 election; in the next Parliament, it will have none.
The right-leaning, libertarian ACT party, a traditional coalition partner for National, won a single seat, with its leader, David Seymour, returned to Parliament.
Gareth Morgan, a millionaire making his first attempt at Parliament as the leader of the Opportunities Party, received 2.2 percent of votes, too few to win a seat.