Anderson took 6-40 from 29 overs - his 30th Test five-wicket haul - as England bowled their hosts out for 381.
He dismissed Angelo Mathews for 110 but Sri Lanka eked out a good score from 243-6, Niroshan Dickwella making 92 and Dilruwan Perera 67. Dickwella fell painfully short of an elusive Test century when he gifted Anderson his fifth wicket, chipping to Jack Leach at mid-off for 92, his highest score in 41 Test appearances.
It was another improved batting performance from Sri Lanka after their woeful start to the first Test, with multiple contributors.
England fell to 5-2 in reply before Root's enterprising 67 not out from 77 balls led England to 98-2 at the close.
He put on 93 with Jonny Bairstow, who is 24 not out, to steady England after openers Dom Sibley (0) and Zak Crawley (5) both fell, once again, to left-arm spinner Lasith Embuldeniya.
Embuldeniya took two wickets in his first 19 balls after England's spinners had earlier bowled 64 wicketless overs.
Mark Wood took 3-84 in support of 38-year-old Anderson, who became the oldest fast bowler to take a five-wicket haul in Asia.
James Anderson also went past Glenn McGrath for the second place among pace bowelers who have taken the most number of 5 wicket hauls.
All 10 wickets fell to the quick bowlers - the first time that feat has been achieved in Sri Lanka since 2001.
Root, who scored 228 in the first Test, batted superbly and swept the spinners, both conventionally and reverse, at almost every opportunity. He went past Geoffrey Boycott (8,114) as the sixth highest leading run scorer for England. Root, who is playing his 99th Test, passed 8,000 Test runs while making 228 in last week's first Test, and had taken that tally to 8119 by the close today.
England's leading Test run-scorers
Alastair Cook 12,472
Graham Gooch 8,900
Alec Stewart 8,463
David Gower 8,231
Kevin Pietersen 8,181
Joe Root 8,119
Geoffrey Boycott 8,114