Bosnia was a bit unlucky to lose a pair of one-goal games to start the tournament, but the team goes home with its first World Cup win after Miralem Pjanic scored a goal and assisted on another, while Edin Dzeko and Avdija Vrsajevic also found the net for the Bosnians.
Iran entered the contest with a chance to advance, but the team needed to beat Bosnia and have Argentina top Nigeria in the other Group F match.
And while Argentina did its part, Iran fell behind 2-0 in the first hour of the game before scoring its only goal of the tournament in the 82nd minute through Reza Ghoochannejhad.
Dzeko nearly scored inside of four minutes when he fired a shot on goal from eight yards that goalkeeper Alireza Haghighi did well to tip over the crossbar.
But the Manchester City striker got off the mark 20 minutes later when he dribbled to the top of the penalty area and drove a low shot off the right post and into the net.
Iran almost answered immediately as Masoud Shojaei struck the crossbar, but Bosnia doubled its lead in the 59th minute.
A giveaway in Iran's defensive third allowed Tino Susic to play Pjanic into the area, where he smashed a first-time shot past Haghighi.
Ghoochannejhad gave his team a bit of a lift when he turned home a cross from Javad Nekounam eight minutes from time, only for Bosnia to answer back one minute later through Vrsajevic, who drove a low shot inside the far post from a tight angle to seal the win.
The result leaves Iran on the bottom of Group F, while Bosnia finishes in third place, one point back of second-place Nigeria.