Mashrafe picked up the injury during a training session shortly after he attended Bangladesh team's formal press conference in Mirpur ahead of the tour.
"Mortaza (Mashrafe) injured his left hamstring during training today. He received immediate MSK ultrasound examination which has revealed a grade 1 injury," Bangladesh Cricket Board senior physician Debashis Chowdhury said in a statement.
"It is a recurrent injury that could take around three to four weeks to recover from. Therefore, he is ruled out from participation in sporting activity for a month," he added.
BCB named Tamim as interim captain in Mashrafe's absence as regular vice-captain Shakib Al Hasan was rested for the series.
All-rounder Mohammad Saifuddin was also ruled out for the series after he aggravated an old back injury, said BCB cricket operations chief Akram Khan.
Pace bowler Taskin Ahmed and all-rounder Farhad Reza were immediately recalled as replacements for Mashrafe and Saifuddin.
Bangladesh will play three one-day internationals in Sri Lanka respectively on July 26, 28 and 31. All the matches are scheduled in R Premadasa Stadium in Colombo.
Mashrafe earlier at the press conference refused to confirm if he would retire after the Sri Lanka series and likened his situation to former India captain M.S. Dhoni.
Mashrafe and Dhoni both were expected to clear their retirement plan after the recent World Cup in England in which they struggled with individual form.
While Dhoni, who made a fifty in India's losing semi-final to New Zealand, remained silent on his future, Mashrafe chose to continue as team captain.
"To be honest, I don't feel embarrassed or disappointed with it (retirement talks). It's normal everyone will consider my performance from their point of view," said Mashrafe.
"As a player I am not close to M.S. Dhoni as he scored over 10,000 runs in ODIs. But at least in every press conference he has been asked the same question (retirement). I think we should see it normally,"
"Being a player I could not deliver my best in World Cup, both as a captain and a player and the team also failed to go to the semi-final.
"So it's normal the question will be raised. I also see it this way. There's is nothing else to consider," he said.
Mashrafe picked up just one wicket in Bangladesh's eighth place finish as the team recorded only three wins against fellow strugglers South Africa, West Indies and Sri Lanka.