Marseille was missing several regulars from its starting line-up as it played a fifth game under interim coach Nasser Larguet, who has had to step up from his role as director of the club's youth academy since the firing of Andre Villas-Boas.
It had won just two of its previous 13 games altogether, slumping down into mid-table, but this victory lifts it back up to sixth, within a point of the European places.
Amid growing speculation that they could appoint former Argentina coach Jorge Sampaoli -- who is currently at Atletico Mineiro in Brazil -- as the permanent replacement for Villas-Boas, interim boss Larguet saw defender Alvaro Gonzalez put Marseille ahead on 14 minutes.
The Spaniard volleyed home from the edge of the six-yard box after Dimitri Payet's cross from the left was blocked and dropped into his path.
Payet's backheel then released Luis Henrique, with the Brazilian teenager reaching the byline before cutting the ball back for Khaoui to score with a first-time finish.
Amine Gouiri pulled a goal back for struggling Nice just after the break, but Khaoui scored again in the 53rd minute, picking his spot when another Payet delivery was headed down into his path.
Marseille were still subjected to a nervy finish, though, with 20-year-old Malik Sellouki coming on for his top-flight bow and pulling it back to 3-2 late on.
Gouiri then hit the post with a last-gasp free-kick as Marseille held on.