Niroshan Dickwella made a positive start for Sri Lanka after Sarfraz Ahmed inserted the opposition at the toss.
Junaid Khan enjoyed another productive outing with the ball, taking out Gunathilaka early before coming back to take two more wickets after the second drinks break.
Angelo Mathews scored a fluent 39 in a 78-run stand with Dickwella as SL overcame a wobble to reach 161 for 3 by the 31st over.
Mohammad Amir delivered the crucial breakthrough straight after drinks when he dismissed Mathews. He went on to grab another wicket in a furious spell as SL slipped to 167/7.
Suranga Lakmal scored a useful 26 down the order in a 46-run stand 8th wicket stand with Asela Gunaratne to take SL to a respectable 236.
Fakhar Zaman scored a 36-ball 50 in a opening stand of 74 with Azhar Ali.
Even as Sri Lanka chipped away at the wickets, there were constant fumbles and misfields that released pressure.
Nuwan Pradep picked up 3 for 60 in his quota of 10 overs as Sri Lanka came storming back to take control of the game.
Sarfraz Ahmed began the rescue act even as Pakistan kept losing batsmen at the other end to slip to 162 for 7.
Sarfraz eventually found an able partner in Mohammad Amir, who was shrewd enough to turn the strike over and play percentage cricket.
As Pakistan brought the target down, Sri Lanka began to falter on the field. Lasith Malinga had two catches dropped off his bowling at the death.
Sarfraz Ahmed hit the winning runs to finish unbeaten on 61 and helped Pakistan setup a semifinal date with hosts England.