Resuming at the overnight score of 261-4, the tourists revelled on the easy-paced wicket to move to 347-5 by lunch on the second day at the Galle International Stadium.
Khan, who came in to bat at 19-2 on the first morning and ended the day on 133, was untroubled by both Sri Lanka's seamers and spinners.
The 36-year-old, who is playing his 90th Test, has so far batted for eight hours, hitting 15 boundaries and a six in his 24th Test century.
The visitors added 32 runs in the first hour when left-arm spinner Rangana Herath broke through for Sri Lanka by trapping Shafiq leg-before. The batsman's appeal to the TV umpire went in vain.
Also Read
Sri Lanka came close to removing Khan when he was on 156, but seamer Shaminda Eranga spilled a sharp return catch as the batsman failed to keep a drive along the ground.
Pakistan wicket-keeper Sarfraz Ahmed was unbeaten on 28 at the break, having added 54 valuable runs for the sixth wicket with Khan.