Dinesh Chandimal made 126 and Rangana Herath 61 as Sri Lanka benefited from dropped catches at Chester-le-Street to move their overnight 309-5 to 475.
Anderson, the bowler to suffer from England's errors, returned to trap Herath lbw on the way to 5-58.
England then eased to a target of 79.
Cook reached his personal landmark five runs into an unbeaten 47.