Marega maintained his fine form in the competition, extending his tally to five goals in six matches.
The 27-year-old doubled the Dragons' lead from the penalty spot in the 42nd minute.
Three minutes later, Feghouli halved the deficit from the spot as the hosts went into the break trailing.
After the restart, Sergio Oliveira regained Porto's two-goal lead with their third goal in the 57th minute but Eren Derdiyok gave the Lions hopes of fighting back with his 65th-minute effort. However, Feghouli's missed penalty two minutes later dashed such hopes as they settled for a spot in the Europa League.
The result meant Porto ended their group fixtures without a defeat as they sit at the summit of Group D with 16 points from six matches.
Nigeria's Henry Onyekuru was introduced for Ryan Donk in the 46th minute while compatriot Chidozie Awaziem replaced Sergio Oliveira in the 82nd minute.