The defender put into his own net during injury time, after Julio Cesar's error appeared to have clinched the Europeans a deserved draw in Switzerland
The Inter keeper had previously spilled a straightforward effort from Vedad Ibsevic and could only watch as the ball finished in the net, cancelling out an earlier strike from Marcelo which had given Mano Menezes' team the advantage in the opening exchanges of the match.
Playing in front a deeply partisan crowd in favour of the European side, Brazil nevertheless started on the front foot, and with just three minutes on the clock took the lead with a delightful goal. Pressure on the Bosnian back line paid off when the ball ended at Dani Alves' feet just outside the area, and a sweeping pass found his fellow full-back Marcelo free and charging towards goal.
The Real Madrid man barely broke his step as he blasted past a helpless Asmir Begovic for his third international goal.
The strike appeared to be the cue for the Selecao to take control of the game, but BiH had clearly not read the script; although they were aided by some disastrous defending from the South Americans. David Luiz gave possession away cheaply in his own half, and a tame shot by Vedad Ibisevic wriggled past Julio Cesar for the equaliser, with the custodian clearly embarrassed at his attempt to repel the shot.
Mano Menezes' men struggled with a BiH team who were determined to use their physicality to impose themselves on the game, with far too many passes going astray in the wake of pressure from the midfield.
With 20 minutes played, however, it really should have been 2-1. An exquisite ball from Ronaldinho found Leandro Damiao, and after the Internacional youngster saw his effort parried by Begovic. Hernanes was denied the rebound by a superb last-ditch tackle from captain Emir Spahic.
At the other end, Edin Dzeko gave the Brazil defence serious problems after a slow start, and both he and Roma starlet Miralem Pjanic could have added a second for the Europeans as the game went into half-time still deadlocked.
Having been relatively quiet before the break Neymar called Begovic into action following the restart with a decent effort from distance, but the goalkeeper saved comfortably and held onto the ball.
The Brazilians' patient approach play contrasted sharply with the smash and grab football played by the Europeans, and both ends saw action; Mismimovic flashing a chance just past the left post as BiH pushed for a famous victory.
Hernanes was unlucky to see his header fizz past the post after an excellent cross from Marcelo, but it was a rare glimpse of quality from a Brazil side that appeared to be meandering towards a draw. A brilliant pass from Elias, however, should have supplied the second, but after making space in the box Neymar shot straight at Begovic to waste a golden opportunity.
Just as it appeared that BiH would hold on for the draw, Sasa Papac ended his side's hopes. Substitute Hulk fired strongly across the area and the defender deflected the ball past his own keeper to the obvious delight of the Brazil team, who snatched victory in the final minutes of an entertaining encounter, but one in which they were far from at their best.