Zenit hold on to progress at Porto's expense
The draw means Zenit finish second in Group G on nine points, behind surprise-package APOEL Nicosia on their head-to-head record after the Cypriots lost 2-0 at home to Shakhtar Donetsk
Porto have to settle for a Europa League spot, ending third on eight points.
The Portuguese champions knew only a win would put them through but though they commanded the game from the off they failed to find a way past the inspired Malafeev, who had a night to remember.
The 32-year-old keeper made a series of good saves, denying clear-cut chances for Djalma, James Rodriguez, Kleber and Hulk on a great night for his side.
"We missed goals and more goals," said Porto coach Vitor Pereira. "We showed quality up front but lacked effectiveness and the passage of time favoured Zenit. We leave the Champions League with the feeling of deserving to qualify,"
Zenit, who came from behind to beat Porto 3-1 in Russia, looked to have a draw in mind as they kept their defensive shape despite Porto's strong start.
The hosts soon took control of midfield and fenced off Zenit's counter-attack threat thanks to hardworking midfielders Fernando and Joao Moutinho.
Steady passer Moutinho put Angolan international Djalma through on goal after five minutes but Malafeev set the tone for the night with an excellent reflex save.
Zenit were toothless in attack and lacked any clear chances, struggling to build up play from their half, but they held on stoically in defence to reach the break with the scoreline that suited them.
"We had chances and kept trying but they just parked the bus in the back," said a frustrated Kleber.
Porto kept pressing forward in the second half but remained wasteful.
Hulk found space in the box and toe-poked the ball just wide of Malafeev's goal from a tight angle, while James and left-back Alvaro Pereira also missed excellent chances.
It still looked like a matter of time before Porto would find a way through but Malafeev was equal to everything they threw at him and Luciano Spalletti's side held on for a memorable qualification.
"This is a big disappointment, we should have gone through to the last 16, that was our ambition. We did all we could but things just did not go our way," said Moutinho.
The group stage exit will increase the pressure on Porto Pereira, who has fallen out with the fans after a string of bad results.