VAR came to the visitors' aid early on after a blatant foul on Hirving Lozano in the penalty area was missed by the on-field officials, with the referee awarding a spot-kick converted by Lorenzo Insigne in the 15th minute.
Udinese continued to offer more attacking threat in the second half, but against the run of play Bakayoko, on loan from Chelsea, popped up with a 90th-minute header to send Napoli fifth, above Juventus who play Sassuolo later on Sunday.
Udinese stayed 13th with 16 points and are without a win in six league games.
A fine stop from Meret denied Lasagna his second of the game midway through the second half. Bakayoko headed his first Napoli goal in off the post to spark wild celebrations.
The result provided Napoli a huge boost as they had won just one of their last five Serie A matches before Sunday. The three points allowed them to stay in touch with the top four.
"I am happy (with his first goal)," Bakayoko told Sky Sports. "Especially because it was the winning goal.
"We were going through a difficult period after the defeat against Spezia (on Wednesday), and we had to give a response. It was very important to react with a victory."