Khan showed no signs of rustiness after Pakistan playing a Test match for over six months and made a splendid 133 off 228 balls with 11 fours a six.
Fast bowler Dhammika Prasads (2/54) twin strikes had Pakistan in early trouble at 56/3 before Khan dominated century stands with captain Misbah-ul-Haq (31) and Asad Shafiq, who was not out on 55 at stumps.
Khan twice used the Decision Review System successfully and overturned umpires decisions in equaling countryman Mohammad Yousufs record of 24 test centuries.
He also got a lucky escape on 68 when Mahela Jayawardene, playing for the last time at Galle, dropped a sitter.
Prasad had removed Pakistans openers in quick succession as the visitors struggled in the morning session after Misbah won the toss and elected to bat under overcast conditions.
Prasad (2/33) claimed the wickets of Ahmed Shehzad and Khurram Manzoor cheaply in a lively opening spell and ace spinner Rangana Herath clean bowled Azhar Ali for 30 to have Pakistan in early trouble.
PRASAD EXPLOITS PAK RUST
Pakistan top order batsmen showed rustiness from a long layoff of over six months since last playing a test match in January, when it defeated Sri Lanka at Sharjah to level that series.
Prasad, who missed the home series against South Africa, came back strongly with the new ball as he replaced spinner Ajantha Mendis in the playing XI. The right-arm fast bowler broke through with his third delivery as Shehzad edged the ball onto middle stump, and then trapped Manzoor leg before wicket to leave Pakistan at 19-2. Ali, who hit a century in Pakistans monumental run-chase at Sharjah, looked confident and hit five boundaries before he was undone by Heraths superb delivery that spun away from the right-hander and hit the off stump.
LUCK FAVOURS KHAN
Khan, who successfully overturned umpire Bruce Oxenfords caught behind decision off Prasads sharp delivery before lunch, completed his 29th test half century with a punching off drive to cover boundary off Dilruwan Perera before turning the offspinner for a single and then hitting a towering six over wide long on.
Khan was again spot on when on 58 he overturned another Oxenfords decision after he was ruled out lbw off Pereras delivery that television replays showed would have missed the top of stumps by a whisker.
The luck continued to favor Khan as Jayawardene smartly anticipated Khans reverse sweep but could not hold onto two-handed catch in the lone slip.
GUARD OF HONOUR
Earlier, Sri Lankas most accomplished batsman Jayawardene led the team onto the field with children giving him a guard of honour with raised bats and his team-mates clapping from the sidelines.
Jayawardene will be playing his last test at his favourite Galle International Stadium and will retire after the second test at his home ground in Colombo.
The stadium was decorated with giant hoardings and billboards of Jayawardene to pay tribute to the great Sri Lankan, who has scored over 10,000 runs in both test matches and one-day internationals.
Brief scores: Pakistan: 261/4 in 88 overs (Y Khan 133*, A Shafiq 55*; D Prasad 2/28)