Karoline Deyhre Brevang scored from a break with 12 seconds remaining to secure a dramatic 24-23 victory for the defending Olympic champions at the Copper Box, where the Danes needed a victory to maintain any hopes of making the last eight.
Sweden exited after losing 25-24 to Spain in Group B, which France secured with a 24-21 win over South Korea. The South Koreans advanced to the last eight thanks to Norway's victory.
"It is much tougher in women's handball than it used to be," Sweden coach Per Johansson said.
Russia, Brazil, Croatia and Montenegro all reached the quarterfinals from Group A, leaving only elimination knockout positioning to play for on the last day of group play.
It was another day of closely contested matches, as Russia beat Brazil 31-27 and Croatia was a 31-25 victor over Montenegro in Group A. Britain remained winless after losing 31-25 to Angola.
Russia coach Evgeny Trefilov was not quite satisfied with the victory despite the 2008 silver medallists bouncing back from a surprise loss to Croatia to take control of the group.
"It is very difficult to understand women in general," said Trefilov, who gave his players an effective halftime pep talk. "Apparently (my team talk) kind of helped."
Croatia overcame an impressive effort by Montenegro goalkeeper Marina Vukcevic to beat its Balkan neighbour, with its players singing a victory song at "The Box That Always Rocks," as the venue is nicknamed, after jumping ahead of their Adriatic Sea neighbour in the standings.
The always raucous crowd went wild after a France steal set Pineau off alone on South Korea goalkeeper Ju Hui, who couldn't deny the Frenchwoman as the gold medal hopefuls moved top with one game left.
"That goal liberated us," Pineau said after making it 23-20 with two minutes to play. "I never would have imagined us finishing first in such a tough group. It's cool, no? Let's see who we meet (in the quarterfinals)."
The momentum shifted after influential South Korea wing Jung Yu-ra came out with a knee injury just before France took the lead for good at 18-17, as the Asian team endured its first loss of the tournament.
Britain's women came closer to a first victory but despite Marie Gerbon's game-high nine goals, the hosts couldn't muster enough as Nair Almeda scored eight goals for the Africans.
"It's massively disappointing, most of us are going to go away and cry ourselves to sleep," Britain's Holly Lam-Moores said.
Paul Logothetis can be reached at: www.twitter.com/PaulLogoAPSuggest a correction