The ballot was among the demands the Green Party made during talks to join Prime Minister Jacinda Ardern's progressive coalition government after the 2017 election.
Justice Minister Andrew Little said the government had agreed to the timetable, and the result of the referendum would be binding.
"It will be held at the 2020 general election," he told reporters, adding "there is a bit of detail still to work through."
Ardern's government has already moved to legalise medicinal cannabis, with legislation on the issue working its way through parliament.
An opinion poll last year found 65 percent of New Zealanders also supported legalising the drug for recreational use.
Pro-reform campaign group New Zealand Drug Foundation welcomed the vote, with its chief Ross Bell saying the current approach to regulating marijuana was outdated and it was time for a change.
"Cannabis is New Zealand's most common illegal drug, 50 percent of the country have tried it," he said.
"We're still trying to address the problem through a law enforcement approach. We're still criminalising people and not providing help to people who have a cannabis dependency."
The conservative National Party opposition leader Simon Bridges said he would be voting against legalisation and accused the government of trying to deflect voters' attention from issues such as the economy and the rising cost of living.
"I'm pretty cynical that you've got a government here that wants to distract from the core issues of a general election," he said.
Ardern strongly supported legalising medical pot but has not revealed her personal views on recreational marijuana, saying only she does not believe cannabis users should be jailed.
The debate in New Zealand comes as New York governor Andrew Cuomo called Monday for the drug to be made legal for recreational use in his state, including America's most populous city.