Belgium scraped a 60-58 win at Portugal on Thursday night to win Group A of the EuroBasket Additional Qualifying Round.
By finishing first ahead of Bosnia and Herzegovina, Belgium will take on Group B winners France in an all-or-nothing showdown to determine the last team to reach the EuroBasket in Poland.
Both Bosnia and Herzegovina and Belgium had three wins and one defeat, but the Belgians won the tie-breaker by virtue of their resounding victory over the Bosnians earlier this week.
That gave them a better goal differential in the meetings between the sides.
Thursday's game was a thriller that wasn't decided until the end.
Portugal knotted the contest at 57-57 when Carlos Andrade went to the charity stripe and sank two free-throws.
Jef Van Der Jonckheyd went to the other end and drilled a three-pointer with 54 seconds remaining for Belgium, a shot that proved to be the game-winner.
Belgium ended up fouling Joao Gomes with 19 seconds left and the forward made the first free-throw but missed the second.
He grabbed the offensive rebound, but Portugal star Carlos Andrade (16pts, 7rbs) turned the ball over with three seconds to go and Belgium held on for victory.
Roel Moors scored 15 points for Belgium, with Christophe Beghin poured in 12.
Axel Hervelle had 11 rebounds to go with his nine points.
Portuguese Coach Moncho Lopez:
"The first words are to our captain José Costa, the most clever player I ever worked with, very compromised with all the coach work.
The fact we didn't win any game in the qualification hurts a lot when these players, coaches and federation members deserved more, because of the good conditions they gave me to do my job."
Belgium Coach Eddy Casteels:
"This was a typical Belgium game, with players afraid to qualify, nervous. It was an intense game, very physical. I respect how the Portuguese team handled the situation."