Croatia were hoping for France to beat Portugal in the final game.
Their destiny was not in their hands despite a 30-27 win against Tunisia.
But a last-minute winner in a thrilling game saw the Portuguese celebrate wildly.
France still managed to qualify top of the group due to their previous results but it meant disappointment for two-time Olympic champions Croatia.
Germany also went through after a solid 34-26 win over Algeria.
The Europeans were in control for most of the match with Julius Kuehn top scoring for the winners with eight goals.
The north African side had no chance of qualification after losing their first two games of the qualifying event.
Germany join Japan, Denmark, Argentina, Bahrain, Spain, and Egypt in the 12 team competition.
Sweden also secured their spot with a 32-25 victory over Slovenia.
"The defence was really good and everyone did his job. I am really happy with the team and incredible proud,” said Sweden coach Glenn Solberg to the official IHF website.
Norway beat South Korea 44-32 to advance to Tokyo 2020. Norway's result also put Brazil through after their 26-24 win against Chile.