Updated

Jerryd Bayless matched a career high with 31 points and the Toronto Raptors pulled off the biggest comeback in franchise history, beating the Detroit Pistons 120-116 on Saturday night.

Toronto overcame a 25-point second-half deficit to end a four-game losing streak. The victory was just the Raptors' third of the season on the road.

Andrea Bargnani added 22 points, including a pair of key 3-pointers in the fourth quarter, and Leandro Barbosa scored 20. Ben Wallace had a career-high 23 points and 14 rebounds, while Rodney Stuckey also scored 23.

Toronto shot 65 percent from the floor in the first half, but committed 14 turnovers that led to 29 Detroit points. Meanwhile, the Pistons only turned the ball over once on their way to a 72-53 lead.

Detroit led by 25 midway through the third period, then faltered on defense. The Pistons' strong shooting kept the margin at 99-83 going into the fourth, but Toronto kept the rally going.

Bargnani's 3-pointer pulled the Raptors within 106-98 with 8:18 to go, and ex-Piston Amir Johnson followed with a three-point play.

The Raptors cut it to 110-107, and Bargnani tied it with another 3 with 2:05 left. After a Pistons miss, Bayless hit a 3-pointer and then answered Ben Wallace's putback to give Toronto a 115-112 lead with 49 seconds to go.

Stuckey made one of two free throws and Bayless did the same, leaving it a three-point game with 20 seconds left.

Tayshaun Prince threw away a lob on the ensuing inbounds play, and Bayless clinched the game from the line.

NOTES: The Raptors overcame a 22-point deficit to beat the Clippers in November 2009. ... Each of the first two quarters ended with long 3-pointers at the buzzer. Tracy McGrady's 60-footer at the end of the first was ruled to have been too late, but Barbosa's shot from just inside halfcourt counted to end the first half. ... Wallace hit a meaningless 3 at the end of the game — his first in four years.