Foakes began by reaching 107 in Galle, adding 20 to his overnight score to become England's 20th debut centurion in a total of 342 all out.
The hosts responded by reaching 136 for five at tea, Foakes opening his wicketkeeping account with by taking a simple chance off only his second ball and later added a smart piece of glovework to to whip off Dinesh Chandimal's bails.
The second session ended four balls early when Rory Burns was struck on the top of his back while fielding at short leg, receiving treatment as he lay on the field but eventually walking off unaided.
The Sri Lankan innings had mirrored England's day one efforts, with a flurry of activity early on and a more sensible passage of play led by Angelo Mathews' 52 not out in the afternoon session.
The hosts were 42 for four at lunch but went on to add 94 for the loss of Chandimal in the next two hours.
England began the day on 321 for eight, Foakes immediately banishing any nerves by driving the first ball of the morning for four past extra cover.
He had 95 when Jack Leach nicked to slip, Dilruwan Perera's fifth victim, but a strong pull and a punch down the ground off Suranga Lakmal saw him over the line.
In doing so he became the 20th Englishman to hit a hundred in his first Test and just the second wicketkeeper, following Matt Prior in 2007.
After a few minutes to compose himself, Foakes returned behind the stumps and within seconds bagged his first dismissal in international cricket – a simple gather after Dimuth Karunaratne felt for Anderson's outswinger.
It was the start of a desperate top-order display. Kaushal Silva fell lbw to a full inducker from Sam Curran, Kusal Mendis edged Leach to Ben Stokes at slip and Dhananjaya de Silva was bowled by Moeen Ali after botching an ambitious sweep.
Mathews and Chandimal knuckled down to some hard work to blunt England's charge, only parted when Adil Rashid spun one past the latter's outside edge and Foakes produced a fine piece of keeping to stump him.