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.

It is the SDLP's turn to hold the position and the party nominated the north Belfast councillor last week.
The decision was ratified at a full meeting of Belfast City Council on Monday night.
Maire Hendron of the Alliance Party has been elected deputy mayor - the first time women have held the two top posts.
Ms Mallon, 34, said being chosen as lord mayor was a tremendous honour.
"I want to congratulate Máirtín Ó Muilleoir on a fantastic year in office and thank my own party for nominating me to take on such a privileged position," she said.
"I have had the privilege of representing the Oldpark area, the place I grew up in, for the last four and a half years.
"The most wonderful part of being a councillor, for me, continues to be the many unsung heroes I get to meet - all those people who through their compassion and selflessness, makes this city the special place that it is."
She said she wanted to take the lord mayor's role "out of city hall and into people's lives".
"I want to connect with those who at times feel invisible in our city. I want to celebrate and showcase our unsung heroes who really are Belfast's first citizens," she said.
"Belfast is a city for everyone, where everyone belongs and where we are all the better for having each other."
Ms Mallon is only the third woman to hold the office of lord mayor of Belfast, following the Ulster Unionist Party's Grace Bannister in 1981 and Naomi Long of the Alliance Party in 2009.
With Lydia Patterson of the DUP also serving as high sheriff, it is the first time that all three civic dignitaries in Belfast are women.
After her appointment, the city's new deputy lord mayor said she was "looking forward to the year ahead".
Ms Hendron added: "During my year in office, I would hope to play my part in building a more inclusive city that is open to all.
"I want to work with all groups from different backgrounds to further improve Belfast's diversity, which is a source of strength for our society."
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.
[NEXT_CONCEPT]
The SDLP's Nichola Mallon has become the new lord mayor of Belfast, succeeding Sinn Féin's Máirtín Ó Muilleoir.