The Portugal winger opened the scoring with a third-minute penalty, before then netting his 50th Porto goal just seven minutes later.
Bayern did pull a goal back thanks to Thiago Alcantara’s strike after 28 minutes, but frontman Jackson Martinez ensured Porto recorded their first-ever home win against the Bavarians by then slotting home 20 minutes after half-time.
The home side made a dream start to proceedings when they were awarded a penalty after just 90 seconds when Bayern midfielder Xabi Alonso was caught in possession just outside his penalty area by Martinez.
The ever-alert Colombia international then bore down on Manuel Neuer, before rounding the goalkeeper, only to be upended by the shot-stopper just before he was able to put the ball in the back of the net.
Referee Carlos Velasco Carballo wasted no time in pointing to the spot, although Neuer was lucky to escape with only a booking, before Quaresma kept his cool to send the Bayern No 1 then wrong way from the spot.
However, if Bayern head coach Pep Guardiola thought that piece of defending was bad, then he would have been dismayed to see his team make an even worse error after 10 minutes when centre-back Dante was also robbed of the ball in a dangerous position by Quaresma.
Hardly believing his luck, the Portuguese raced clean through on an unprotected Neuer to fire the hosts into a shock 2-0 lead, a goal that was greeted with delirium by the home fans in a rocking Dragao.
The stunned visitors, whose only effort on goal inside the opening quarter of the match was a Robert Lewandowski header that just cleared Fabiano’s crossbar, got themselves back into the contest by scoring a vital away goal just before the half-hour mark.
Bayern right-back Jerome Boateng made a storming run down the right flank and the defender’s low centre somehow made its way all the way through a posse of players in the box, before an unmarked Thiago found himself in the right place to score his first-ever Champions League goal from close range.
But if that strike came against the run of play, Porto’s players did not let their heads fall, with Julen Lopetegui’s men responding by almost scoring a third goal just before half-time, only for the lively Carlos Casemiro to head Quaresma’s inch-perfect free kick from the right-hand byline wastefully over the bar.
But that miss was soon forgotten as Porto came out after half-time again attacking right from the off in search of a third goal, with Neuer having to be at his very best to prevent team-mate Boateng from scoring an own goal with a world-class stop at his near post.
The Portuguese champions, though, were not to be denied, as just minutes later Martinez fired them 3-1 in front. Yet again Bayern defender Dante was all at fault for the goal after misjudging the flight of the ball and allowing the Porto captain a one-on-one with Neuer.
Martinez still had work to do, however, to calmly round the German and net his sixth strike in just seven Champions League games this season, and all this after the player was a doubt in the build-up to the game with injury.
Thereafter Porto managed to keep their opponents at arm’s length to ensure they take a two-goal lead with them into the return leg at the Allianz Arena on Tuesday, a tie in which they will be without both their first-choice full-backs through suspension as they look to finish the job in Bavaria.