Dutch striker Mark de Vries sent debt-ridden Hearts into the lucrative group stages of the UEFA Cup with a stunning double strike in the Estadio Municipal in Braga.
De Vries only played courtesy of pain-killing injections in a foot injury but it was a gamble that paid off spectacularly.
Manager Craig Levein had played down the possibility of the striker playing but as kick-off approached it was obvious he had an ace up his sleeve.
A year ago, the manager erred badly with his tactics when Hearts went out to Bordeaux but he made amends with his decision to play de Vries.
SC Braga threatened first and Wender shot narrowly over from ten yards but Hearts responded and Phil Stamp tested Paulo Santos with an angled volley.
But there was a major setback for Hearts after 12 minutes when Joao Tomas put the Portuguese in front when he lobbed the ball over Craig Gordon from the tightest of angles after uncertainty in the Hearts defence.
Hearts had a let-off six minutes later when Neil MacFarlane and then Patrick Kisnorbo gave the ball away but Paulo Sergio's final shot finished wide.
Hearts responded and a shot from the edge of the area from Robbie Neilson bounced off Wender and went wide off the post.
The equaliser came after 27 minutes when captain Paulo Jorge was short with a headed passback and de Vries nipped in to prod the ball past Paulo Santos for an invaluable goal.
It was the lifeline that Hearts needed and they visibly grew in confidence as half-time approached.
There was a flutter when Jaime curled a 22-yard free-kick narrowly wide with Gordon rooted to his line.
The game was not much of a spectacle with referee Anton Stredak booking five players in the first half and constantly halting play for free-kicks.
But it worked to Hearts' advantage and they effectively put the tie beyond Braga when de Vries scored their second two minutes into the second half with the aid of a deflection.
It meant that the Portuguese had to score four goals to qualify and the goal stunned the home crowd.
SC Braga tried to get something back and Gordon easily clutched a header from Joao Thomas under his crossbar and then made a superb save to deny Paulo Sergio from distance.
But Paulo Sergio set up the equaliser with 14 minutes left when his corner found Jaime and he bundled the ball home at the far post.