A draw would have been fair - Allegri
The reigning champions extended their winning Serie A run at Juventus Stadium to 25 matches, but they were pushed all the way by their city rivals.
Arturo Vidal gave Juve the lead from the penalty spot after quarter of an hour, but they were soon pegged back by Bruno Peres' remarkable individual effort.
The Brazilian set off from the edge of his own box and ran 75 yards before lashing an unstoppable shot in off the far post - Torino's first goal against Juve in more than 12 years.
Stephan Lichtsteiner's dismissal looked to have ended Juve's hopes of victory, but Andrea Pirlo struck with virtually the last kick to secure all three points, and Allegri feels defeat was harsh on the visitors.
"Perhaps a draw would have been a fair result, but this win makes up for Genoa [a 1-0 defeat], where we deserved to emerge victorious," he said.
"We played well in the first half but struggled after the break. Torino gave us problems on the counter.
"Credit to the lads for tonight's win. They never stopped believing."
Pirlo, meanwhile, revelled in his last-gasp winner - his second league goal of the campaign.
"I followed the move all the way and Vidal did well to see me at the last second. I hit it with all my might and it went in. We're all ecstatic," he told Sky Sport Italia.
"It's brilliant to be able to win the derby in the last minute, especially with 10 men, and it's a great feeling we've treated our fans to.
"The result allows us to continue building momentum. That's the most important thing, then to win it in the way we did tonight makes it even better."