Napoli beat Crotone earlier in the day to leapfrog the Giallorossi, but Luciano Spalletti's men hit back with victory in a clash where they were well matched for long periods in Sicily.
Palermo thought they had taken an early lead when Ilija Nestorovski's hopeful shot squirmed past Wojciech Szczesny at his near post, but their celebrations were cut short by the offside flag.
And it was Roma who opened the scoring after 22 minutes, with El Shaarawy timing his run to meet Clement Grenier's cross and prod through Andrea Fulignati's legs.
Further chances came and went for the visitors, who were then thankful to Szczesny for good saves from Alessandro Diamanti and Michel Morganella at the start of the second half as relegation-threatened Palermo chased an equaliser.
But Roma accelerated out of sight in the final 15 minutes as substitute Dzeko stroked in his 30th goal of the season in all competitions, from Radja Nainggolan's pass, before Peres completed the scoring in stoppage time.