The left-arm spinner finished with five for 68, his 15th haul of five or more wickets in a Test innings, while the fast bowler Nuwan Kulasekara took three wickets as the tourists were all out in the last session after being put in to bat.
Sri Lanka lost the opening batsman Tillakaratne Dilshan for no score before reaching 18 for one in reply at stumps. Fellow opener Dimuth Karunaratne was unbeaten on 12 with Kumar Sangakkara (three not out).
Mominul Haque, who made 55 on debut in the drawn first Test in Galle, top scored for Bangladesh with an impressive 64. Nasir Hossain (48), Jahurul Islam (33) and Sohag Gazi (32) were the other main scorers.
"We thought it [the pitch] would help the seamers. Luckily, I got some wickets but our bowlers bowled well on this track," said Herath. "I didn't get much help before lunch, but after lunch I just kept the ball in the right place and that's why I was successful."
Herath dismissed the Bangladesh captain Mushfiqur Rahim (seven) and Mohammad Mahmudullah (eight) in four overs in the second session before removing Haque, Gazi and Nasir in the last.
"It was a good wicket and the ball was coming nicely on to the bat. Herath did well because he maintained a good line and length," said Haque. "If the outfield had been good our score could have reached 300-320."
Nasir, who put on 59 for the seventh wicket with Gazi, cracked one six and two fours in his 87-ball knock before being the last man out, trapped leg-before by Herath.
Rahim, who became the first Bangladeshi to score a Test double-century in the last match, was bowled while Mahmudullah was caught by Angelo Mathews, who dived from the slips to take a smart catch.The 21-year-old Haque put on 49 for the third wicket with Jahurul to steady the innings after Bangladesh had lost two crucial wickets in the first session.
The hard-hitting opener Tamim Iqbal was trapped leg-before for 10 while Mohammad Ashraful, who scored a brilliant 190 in the last match, was run out for 16.
Jahurul hit just two fours in his patient 129-ball knock before being caught by the wicketkeeper Dinesh Chandimal off fast bowler Shaminda Eranga.
Sri Lanka had struck in the seventh over of the morning session when Kulasekara removed Tamim Iqbal, who was returning to the side after missing the first match.
* Agence France-Presse