Two-time Olympic champion Croatia pulled away from Spain late in the second half to win 30-25 and advance.
The 2008 champions dominated the game with the support of a predominantly French crowd that did not see their side fall behind against their opponents. France will face Spain in the quarterfinals.
Spain trailed by one goal going into halftime and then levelled the match at 19-19 when Victor Tomas scored halfway into the second half. But Croatia went ahead again shortly afterward and then gradually pulled away with Blazenko Lackovic scoring four of his seven goals in the final 10 minutes despite injuring his right ankle early in the match.
Croatia finished top of Group B with 10 points. On Wednesday, the Croats will go into the quarterfinal match against Tunisia unbeaten, a confidence boost in the Balkan nation's campaign for its third Olympic gold.
"It is very nice. Five games, five wins," coach Slavko Goluza said.
Tunisia advanced after beating Argentina 25-23 Monday, with Kamel Alouine scoring seven goals.
Earlier, Iceland crushed Britain 41-24 to remain unbeaten and top Group A with 10 points.
It will face Hungary in the quarterfinals.
"Hungary are a very good team and we will have to fight hard to win against them," said Iceland player Arnor Atlason.
Hungary advanced after Tamas Mocsai scored nine goals in a 26-23 win over Serbia. The Serbs were the better side at the start of the decisive Group B match, and led 11-9 at halftime. Hungary levelled at 14-14 and later scored three straight to take a 21-18 lead, which it never relinquished.
In an earlier Group B match, European champion Denmark beat South Korea 26-24 to advance and face Sweden in the quarterfinals.
Meanwhile, Steven Larsson's nine goals couldn't prevent Britain from going out of the tournament without a win in the group stage.
Handball has never been big in Britain but was given a boost by its participation in the Olympics, where Copper box venue has been packed with raucous crowds. But the British team, which had never competed at the games before, fell to six straight big defeats.
"I am disappointed, but we are a very young team that faced teams that were champions before we even played handball," Larsson said.Suggest a correction