The Surrey wicket-keeper batsman, who knows this could just be a one-off chance as Jonny Bairstow regains fitness, came in with England precariously placed on 103 for five on a Galle pitch notorious for low scores.
Foakes built crucial partnerships including an 88-run seventh wicket stand with Sam Curran, who made 48, to defy Sri Lanka's bowlers.
England elected to bat first in what was Sri Lankan spin legend Rangana Herath's farewell match.
The right-handed Foakes steadied the innings reaching his half-century early in the final session as the tourists lost just three wickets after lunch.
Foakes put on 61 for the sixth wicket with Jos Buttler, who was eventually caught behind off Dilruwan Perera for 38.
Left-hander Curran attacked the bowling, hitting one four and three sixes before falling two short of his fifty to spinner Akila Dananjaya.
Adil Rashid made a useful 35 in a stand of 54 with Foakes that increased the frustration for Sri Lanka's bowlers before he became Perera's fourth victim of the day.
Jack Leach, batting on 14, then survived some anxious moments in the final two overs to give Foakes a chance to complete a momentous debut ton on day two.
Sri Lanka's veteran spinner Rangana Herath claimed his 100th Test scalp at Galle after sending back England skipper Joe Root in the opening session.
Only two other bowlers have achieved 100 Test wickets on one ground -- Herath's legendary compatriot Muttiah Muralitharan who achieved it at Galle, Kandy and SSC Colombo, and England paceman James Anderson at Lord's.
Herath notched up the milestone when Root came down the wicket and missed after a breezy 35.
Root had also steadied England when they stumbled to 10 for 2 after debutant opener Rory Burns was caught behind off Surange Lakmal for nine and Moeen Ali was bowled next ball.
Surrey left-hander Burns had been given the tough task of replacing stalwart Alastair Cook following his retirement in September.
After Root's dismissal, Perera skittled Keaton Jennings four short of his 50 before bowling Ben Stokes around his legs for seven as he attempted to sweep.
Ben FoakesDilruwan PereraEnglandEngland vs Sri Lankarangana herathsam curransri lankaSri Lanka vs Englandsri lanka vs england 2018
First Published: November 6, 2018, 6:01 PM IST