"Getting back to winning was what counted today. We needed it for the league table and for our confidence," Stefano Pioli told Sky Italia.
Milan go into a two-week winter break in second place with 42 points, four behind leaders Internazionale.
"We are showing that we are competitive again, but the final step is always the most difficult one," Pioli added.
Milan's recent dip in form coincided with a growing injury list, and star striker Zlatan Ibrahimovic was the latest player to be sidelined ahead of their trip to Tuscany.
But Kessie put in an impressive performance playing behind striker Olivier Giroud, and opened the scoring by meeting a lay-off from the French striker to fire in after 12 minutes.
Empoli drew level six minutes later when Bajrami drilled a shot into the far bottom corner, before Kessie notched his second of by firing through the goalkeeper's legs.
It was the 25-year-old's 13th league goal of 2021, the most a Milan midfielder has scored in a calendar year since Brazilian great Kaka netted 15 in 2008.
Patrick Cutrone smashed a shot off the bar for the hosts, but Florenzi's free kick found the bottom corner to create a two-goal cushion after 63 minutes.
Hernandez soon smashed in Milan's fourth from six yards to put the game to bed, before Pinamonti pulled one back from the spot.
Milan's evening was made even better by the result in Naples, where a Juan Jesus own goal gave relegation battling Spezia a surprise 1-0 win over Napoli.
The hosts had two goals disallowed and hit the bar late on as they lost a third consecutive home league match.
Thiago Motta's side were winless in six league games heading into Wednesday's clash, but became the first team to win a Serie A match without having a shot on target since statisticians Opta began collecting data in 2004-05.