The next government will inherit a budget surplus of $4.1 billion.
The Treasury's final accounts for the 2016/17 financial year, released on Thursday, show the surplus was slightly above expectations - the pre-election fiscal update in August forecast it at $3.7b.
Tax revenue was largely as expected and there was a slight decrease in government spending.
During the year the economy grew 2.7 per cent, tax revenue increased 7.4 per cent and net debt finished up at $59.5b, which was 22.2 percent of GDP.
The financial year ended in June.
It was the third successive surplus posted by the government, and the largest.
Finance Minister Steven Joyce said it was "a direct demonstration of the benefits of a steadily growing economy".
It had been achieved through solid growth, rising employment and rising real wages against a backdrop of low inflation, he said in a statement.
The government has previously said that if it wins a fourth term most of the surplus will be used up building schools, hospitals and highways.
Labour also has plans for it, including increased funding for health, education and housing.
Mr Joyce, looking ahead, said the government would continue to focus on economic growth combined with further investments in public services and infrastructure.
National and Labour have both said they intend to continue running budget surpluses.