Bangladesh, who came into today's match after two straight defeats in their tournament openers, won the toss and opted to bowl first in Bangalore.
Tamim Iqbal was back in the side for Bangladesh and he made the most of an early dropped catch to score a quickfire 35 off 32 balls and get the underdogs' reply off to a solid start.
Mohammad Mithun was gone in the second over for just one, but Igbal and Rahman then had a second-wicket stand of 44 before Igbal was stumped by MS Dhoni off the bowling of Ravindra Jadeja.
Rahman was also stumped by Dhoni but in odd circumstances as the Indian captain and wicket-keeper dislodged the bails just as the batsman's foot, comfortably in the crease, lifted slightly off the turf.
Bangladesh stayed in touch and by the final over needed 11 to secure one of their great all-time wins.
Back-to-back boundaries from Rahim meant that just two were needed off the last three balls, but Bangladesh could not even force a super over as three wickets in a row fell.
First, Rahim (11) and Mahmudullah (18) were caught in the deep before Dhoni charged forward and ran out Mustafizur Rahman in a frantic finish.
Bangladesh are now out of the tournament, while India can still qualify for the semi-finals and next face Australia in Mohali on Sunday.