The tourists were 38 without loss at stumps after their bowlers, led by off-spinner Moeen Ali, had earned them a handy 139-run first innings lead at the Galle International Stadium.
Keaton Jennings was on 26 and debutant Rory Burns still with him on 11, hoping to make amends after managing only nine in the first innings.
All eyes had been on Foakes at the start of play, when he resumed needing 13 runs for a century in his first test innings with England on 321-8.
The 25-year-old hit the first ball of the day for a boundary but was in danger of running out of partners after Jack Leach became off-spinner Dilruwan Perera’s fifth victim.
However, number 11 batsman James Anderson survived long enough for Foakes to reach three figures before before falling to paceman Suranga Lakmal.
Foakes hit 10 boundaries in his sparkling 107 and is the second England wicketkeeper, after Matt Prior, to score a century on his test debut.
The Anderson-Foakes pairing was soon back in tandem in the field, combining to dismiss Dimuth Karunaratne caught behind off the second ball of the Sri Lankan innings.
With the hosts reeling on 40-4, former captain Angelo Mathews arrested the slide in a 75-run stand with skipper Dinesh Chandimal, who braved a groin injury to make 33.
Foakes effected a smart stumping to dismiss Chandimal off an Adil Rashid leg-break and remained in the thick of the action by pouching a couple of catches.
Mathews hit three boundaries in his patient 52, silencing questions about his fitness and running between the wickets, but fell to Moeen off the first ball after the tea break.
England’s three-pronged spin attack grabbed eight of the 10 Sri Lankan wickets, with Moeen claiming 4-66 as Sri Lanka folded soon after crossing the 200-mark.
Sri Lanka’s top-order collapse mirrored England’s wretched start in the first innings, but lacked a Foakes-style rescue in their middle order.