TORONTO — Amir Johnson made two free throws with less than 3 seconds to play, Andrea Bargnani scored 29 points, and the Toronto Raptors beat Boston 102-101 today to end an eight-game losing streak to the Celtics.

Paul Pierce’s potential winner bounced off the rim as Toronto beat Boston for the first time since a 114-112 road win on Jan. 23, 2008.

Johnson had 17 points and 11 rebounds, Sonny Weems scored 16 points, Leandro Barbosa had 12 and Jose Calderon 11 for the Raptors, who have won a season-high three straight.

Reggie Evans scored a season-high nine points and had 16 rebounds.

The Raptors finished 30 for 39 at the free-throw line.

Nate Robinson led Boston with a season-high 22 points, Pierce and Ray Allen each had 19 and Kevin Garnett and Glenn Davis both scored 12.

Toronto had won just one of its previous 12 against Boston, including six straight losses at home, but handed the Celtics consecutive defeats for the first time this season. Boston lost 89-84 at home to Oklahoma City on Friday.

The Raptors led 82-75 to begin the fourth and extended their lead to 93-81 on a 3-pointer by Barbosa with just over 9 minutes left.

Toronto went cold after that, missing its next 10 field-goal attempts and allowing Boston to storm into the lead with a 17-1 run over the next 5½ minutes. Allen tied it at 94-94 with a 3-pointer from the wing with 3:39 remaining, then made another 3 from almost the same spot on Boston’s next possession.

Johnson ended Toronto’s slump by making a hook shot with 2:46 to play, cutting it to 96-98. After Pierce made one of two from the line and Barbosa hit a jumper, Weems had a chance to put the Raptors ahead, but airballed his 3-point shot with 42 seconds left and Toronto trailing 98-99.

Evans fouled Davis on a drive to the basket with 21 seconds to go and the Celtics’ big man made both, putting Boston up 101-98.

After Weems made a driving layup, Allen lost the ball at midcourt and Toronto recovered. Johnson was fouled by Pierce, making both and giving the Raptors a 102-101 lead with 2.7 seconds to play.

Allen inbounded to Pierce for the final shot. He drove past DeMar DeRozan on the left wing but couldn’t get his jump shot to fall.

Boston’s Rajon Rondo, who left Friday’s game with a strained left hamstring, was held out of the lineup.

His replacement was Robinson, who made an immediate impact by scoring 16 points in the first quarter, including three 3-pointers, as the Celtics led 31-23 after 12 minutes.

Bargnani responded with 15 points in the second and Johnson added seven as the Raptors attacked the basket and got to the line. Toronto made 12 of 16 from the free throw line to build a 61-58 lead at the break.

Shaquille O’Neal fouled out with 7:32 remaining. He had eight points and five rebounds in 20 minutes.

NOTES: Barbosa returned to the lineup after missing six games with a strained left shoulder. … Jerryd Bayless and Peja Stojakovic, acquired by Toronto in Saturday’s five-player deal with New Orleans, are expected to debut in Wednesday’s home game against Philadelphia. … The Raptors will assign forward Ed Davis to Erie of the D-League on Monday. Toronto’s first-round draft pick last June, Davis has not played this season after injuring his right knee shortly before training camp.