Media playback is not supported on this device
Britain led New Zealand 21-0 at half-time and clung on as the All Blacks responded with three second-half tries.
They go on to face Argentina in the quarter-finals at 22:00 BST.
New Zealand were in danger of going out but qualified after Fiji's 24-19 win over the USA, and the All Black Sevens will play Fiji in the last eight.
The other quarter-finals will see Japan take on France and South Africa play Australia.
Britain's men are aiming to secure a medal in Rio, having seen the women's team play so well to reach the semi-finals, then miss out on bronze after a 33-10 defeat by Canada in the third-place match.
New Zealand, meanwhile, have had a difficult tournament, with 15-a-side World Cup winner Sonny Bill Williams being ruled out of the Olympics after partially rupturing an Achilles tendon during the All Blacks Sevens' shock 14-12 defeat by Japan.
The All Blacks Sevens only made it through to the last eight as one of the two best third-placed finishers in the group stage.
Subscribe to the BBC Sport newsletter to get our pick of news, features and video sent to your inbox.
Britain's men finished top of Pool C in the Olympic rugby sevens by beating New Zealand 21-19 to make it three wins from three matches.