Sri Lanka secured a crucial wicket when overnight batsman Younis Khan edged an outswinger from Angelo Mathews to Chandimal, ending a 73-run stand for the third wicket with Azhar.
Younis, who had hoped for a big knock in his 100th Test appearance, scored 40 after making six in the first innings.
Skipper Misbah-ul Haq, seemingly disturbed by a band playing in the stands, requested the umpires to stop the music saying it upset his concentration.
The band obliged, but Misbah did not last long at the crease as he was trapped leg-before by Prasad for 22.
Pakistan lost Asad Shafiq after lunch when he was caught down the leg-side by Chandimal off Chameera for 27, triggering a collapse from a comfortable 274-4.
When Chandimal picked up his fourth catch in the innings to remove Sarfraz Ahmed off Prasad for 16, Pakistan were only 124 runs ahead with four wickets in hand.
Between the two dismissals, Azhar reached his century off the 266th delivery he faced, driving Chameera for two runs.
Prasad bowled Yasir Shah for zero before Chameera claimed the last two wickets, including that of Wahab Riaz, who came out to bat despite suffering a hairline fracture on his left hand.
The third and final Test begins in Pallekele on July 3.
/* Style Definitions */
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-fareast-font-family:”Times New Roman”;