It was a sixth successive league win for Roma and moved the Giallorossi a point above Fiorentina, which hosts title-chasing Napoli on Monday. It is a remarkable turnaround for the club, which won just one of its previous 10 matches in all competitions when Luciano Spalletti replaced Rudi Garcia as coach in January.
"When the squad is without confidence, which is what happened to us, it’s difficult and there’s always something which goes wrong," Pjanic said. "We got into a negative spiral and for a while we played in the same way and it was complicated.
"Now the team has got back to winning with merit and playing well. We are working hard and with confidence it’s always easier. We look above and below: It’s a very open championship and we’re taking it one game at a time."
Roma hosts Fiorentina next weekend.
Extending its unbeaten streak to nine matches, Milan was sixth, six points from third.
Keisuke Honda also hit the crossbar with a free kick in the first half for Milan.
El Shaarawy has tallied four goals for Roma in a boost to Italy ahead of the European Championship. The Italy forward joined on loan from AC Milan in January after a disappointing loan spell at Monaco.
El Shaarawy got Roma off to the perfect start in the fifth minute, cutting inside before curling a magnificent strike into the top right corner from 25 meters out.
Empoli leveled when Roma goalkeeper Wojciech Szczesny punched Mario Rui’s cross onto Zukanovic’s face and it ricocheted into the net.
Roma restored its lead five minutes later. Pjanic’s free kick was straight into the wall but he fired the rebound into the bottom right corner.
Empoli had chances to level before El Shaarawy doubled his tally in the second half, slotting into an empty net after Empoli goalkeeper Lukasz Skorupski could only parry Mohamed Salah’s effort into his path.