Bosnia-Herzegovina lost 74-70 at home to Hungary on Saturday night but still finished top of Group A to advance to the next phase of the additional qualifying tournament in Spain.
All three teams in the group finished with two wins, and two losses, but the order of finish after the goal differential tie-breaker saw Bosnia in first, Bulgaria in second and Hungary in third.
Marton Bader scored 14 points and pulled down six rebounds for Hungary, who also won on Wednesday against Bulgaria.
Edin Bavcic scored 13 points and had 11 boards for the Bosnians.
The home side looked to be in control at the start of the second half after a Nihad Dedovic three-ball stretched their lead to 45-30.
Hungary reeled off seven consecutive points to close the third quarter, however, and opened the fourth with a three-ball to make it a 55-50 ball game.
Then came the Hungarians' game-winning surge.
It started with just under six minutes remaining in the contest.
Behind 64-53, they scored 19 of the game's next 23 points for a 72-68 lead with 22 seconds left and they remained in front thereafter.