The hosts, facing a monumental Sri Lankan first innings total of 587, fought back splendidly to move to 289-4 by tea on the third day at the Zahur Ahmed Chowdhury stadium.
Rahman and Kayes, who came together when Tamim Iqbal was dismissed without a run on the board on Wednesday afternoon, put on Bangladesh's highest second-wicket stand of 232.
Rahman scored 106 in only his second Test and left-handed Kayes celebrated his return to the Test side after two years with 115 to lift Bangladesh to 232-1 soon after lunch.
Unorthodox spinner Ajantha Mendis bowled both batsmen and Kayes had to be taken off the field in a stretcher with a pulled hamstring as he stepped out to loft the ball.
Mominul Haque fell leg-before to Dilruwan Perera for 13, but Shakib Al Hasan and skipper Mushfiqur Rahim remained till tea with an unbroken stand of 30 for the fifth wicket.
Rahman and Kayes had batted through the morning session to take the overnight score of 86-1 to 201 without further loss by lunch.