A three-day lockdown was swiftly imposed in Auckland after the cases were confirmed.
The four new cases are all members of a single family. None had travelled recently.
The restrictions will come into effect on Wednesday, as authorities scramble to trace contacts of the family.
Auckland residents will be asked to stay at home, large gatherings will be banned, non-essential businesses will be shut, and some social-distancing restrictions will be reintroduced in the rest of the country.
New Zealand has fared better than other countries, recording 1,220 confirmed cases and 22 deaths since the virus arrived in late February.
Before Tuesday, New Zealand had gone 102 days without recording a locally transmitted case of Covid-19, one of the few countries to reach such a milestone.
All 22 active cases of the virus before Tuesday's announcement were among returning travellers quarantined in isolation facilities.
Praised internationally for its handling of the pandemic, the country's government had lifted almost all of its lockdown restrictions, first imposed in March.
An early lockdown, tough border restrictions, effective health messaging and an aggressive test-and-trace programme have all been credited with virtually eliminating the virus in the country.
But as infections continue to rise across the world, surpassing 20 million globally on Tuesday, New Zealand officials have warned against complacency.
Announcing the lockdown, Prime Minister Jacinda Ardern said it was necessary to go hard and go early to stamp out the virus.
Auckland - a city of around 1.6 million people - would move to level three restrictions from 12:00 local time (01:00 BST) on Wednesday as a "precautionary approach", she said.
The prime minister said the rest of the country would move to level two of New Zealand's 4-tier alert system of measures against Covid-19.
"This is something we have prepared for," Ms Ardern said at a news conference.
"We have had 102 days and it was easy to feel New Zealand was out of the woods. No country has gone as far as we did without having a resurgence. And because we were the only ones, we had to plan. And we have planned," she said.
Director-General of Health, Dr Ashley Bloomfield, said at least three days of lockdown were needed in Auckland to trace the source of the new cases.
"We're expecting to see other cases," Dr Bloomfield said. "We want to find those other cases as soon as possible and identify or isolate any contacts."
Michael Baker, professor of Public Health at the University of Otago, told BBC's Newsnight programme that even with the most successful strategies in dealing with the coronavirus outbreak "one thing you have to plan for is setbacks".
"I think New Zealand will succeed and get rid of the virus," he added.
In anticipation of a pre-lockdown rush to supermarkets, Ms Ardern and the mayor of Auckland, Phil Goff, called for calm, saying there was no need to panic-buy.
Despite their pleas, large crowds of shoppers were seen queuing at supermarkets on Tuesday night, as they attempted to stock up before lockdown.
One video posted to social media shows customers streaming through the door of a supermarket as a security guard tries to prevent them from entering.