Boston's Rajon Rondo, who had been bothered by a sore right ankle, started for the Celtics and finished with a team-high eight assists in 28 minutes.
The Raptors trailed 61-51 to start the fourth but rallied after Allen and Garnett headed to the bench. Jose Calderon's 3-pointer made it 70-67 with 4:30 left and, after a missed shot by Brandon Bass, DeRozan's layup cut it to one at 70-69.
Consecutive jump shots by Celtics rookie E'Twaun Moore gave Boston a 74-71 lead with 1:19 remaining, but a jumper by Bargnani and a tip-in by Amir Johnson with 26 seconds left made it 75-74 in favor of Toronto.
Stiemsma rebounded Moore's miss and, after failing to score his first attempt, tipped in the go-ahead basket on his second chance.
Bargnani tried to put back DeRozan's miss at the buzzer but his shot didn't fall.
Allen scored seven points in the second as the Celtics took a 40-33 lead at the half.
Toronto outrebounded Boston 39 to 35.
Boston was without forward Paul Pierce, sidelined by a bruised right heel, while Toronto guard Anthony Carter was absent with a sore right shoulder.
The teams meet again in Boston on Wednesday night.