Marseille struggled for inspiration until four minutes into stoppage time when full-back Fanni latched on to a Jeremy Morel cross from the left and scored.
The Provence side, who have 46 points from 25 games, kept the pressure on PSG who travel to Sochaux on Sunday without David Beckham.
The former England captain, who joined as a free agent last month, has yet to regain full fitness, according to coach Carlo Ancelotti, but should be ready when Marseille visit the Parc des Princes next week.
Third-placed Lyon, one point behind Marseille, visit Bordeaux on Sunday.
"When we play simply everything is possible," Fanni told the Canal Plus TV channel. "We did some good things and won because of our heart."
Andre-Pierre Gignac wasted a couple of chances for Marseille in the first half as Valenciennes seemed happy to sit back.
Gignac was set up by Mathieu Valbuena's through ball with keeper Nicolas Penneteau's ill-timed charge allowing the striker to lob him only for his effort to go wide. The French international then fluffed a routine shot from close range.
Three minutes from time Fanni pounced on a Valbuena free kick and his effort shaved Penneteau's left post but he managed to find the net in added time to secure the victory.
The defeat leaves Valenciennes 11th on 33 points.
Nice climbed to fourth on 42 points after teenager Neal Maupay's goal on the hour secured a 1-0 win at Bastia, who were back in their Furiani stadium after playing four games behind closed door.
Furiani was originally closed to supporters indefinitely last December following crowd trouble.
Champions Montpellier beat basement club Nancy 1-0 with an Emmanuel Herrera goal and moved up a place to ninth on 38 points with Nancy stuck on 18 points, five from the safety zone.
Toulouse salvaged a last-gasp 2-2 draw at home to second-bottom Troyes after being 2-0 down when the visitors' Benjamin Nivet put through his own goal in the 88th minute, two minutes after Eden ben Basat scored to give the hosts hope.
Third-bottom Evian Thonon Gaillard's lost 2-1 at Lorient who prevailed with a Jeremie Aliadiere penalty just before the break and a second-half goal from Kevin Monnet Pacquet before Betao got a late consolation for the visitors. Evian have 23 points.
On Sunday, St Etienne will look to regain fourth place when they travel to strugglers Reims.