Referee Davide Massa showed Sosa a second yellow card in the 93rd minute after he brought down Kwadwo Asamoah, and Milan were unable to hang on with 10 men as Dybala made no mistake with a spot-kick awarded for a controversial handball decision against Mattia De Sciglio.
Medhi Benatia had previously opened the scoring for Juventus, but Carlos Bacca's equaliser appeared to be enough for a point as goalkeeper Gianluigi Donnarumma pulled off numerous fine saves.
However, Donnarumma was unable to keep out Dybala from 12 yards, with Juventus consequently opening an 11-point lead at the summit.
The Turin side were by far the better side over the course of the game and eventually made their dominance count, though Milan may feel aggrieved by the nature of referee Massa's penalty decision.
The hosts had reasons for optimism heading into the encounter following their superb home form, last losing a Serie A game in their own stadium back in August 2015.
Milan will also have fancied their chances of getting a good result, though, having won the reverse fixture as well as the Supercoppa Italiana meeting back in December, even if they were beaten when both sides locked horns in the Coppa Italia in late January.
Juventus were in charge from the off and created a number of chances to open the scoring early on, Marko Pjaca - who replaced the ill Mario Mandzukic in the starting XI - testing Donnarumma with a powerful low shot after just four minutes.
Dybala was next to try his luck in the 10th minute, but Donnarumma showed his class with a sublime save, before thwarting Gonzalo Higuain halfway through the first period with yet another stellar reflex stop.
There was no denying Juventus, though, and they grabbed the lead when Benatia found the net at the half-hour mark after a sublime pass from Dani Alves, powering home from close range after beating the offside trap.
Milan slowly grew into the game and they equalised from their first chance of note, Bacca slotting the ball past Gianluigi Buffon with a clever finish from what seemed like an offside position after being sent clean through on goal by Gerard Deulofeu.
The hosts immediately went in search of a second goal after the break and Donnarumma did well to push Miralem Pjanic's free-kick wide for a corner, and the keeper frustrated Sami Khedira moments later with another fine save to keep his side in the game.
Juventus continued to create chance after chance and Donnarumma was fortunate to see Pjanic's shot after a corner routine go behind off the crossbar.
There were more chances for Khedira and Higuain, but neither managed to find a way past the impressive Donnarumma.
But there would be late drama as Milan were reduced to 10 men in stoppage time when Sosa received his second booking for a reckless foul on Asamoah, before the referee awarded Juventus a penalty when Stephan Lichtsteiner's cross struck De Sciglio's arm.
Dybala stepped up to take it and the Argentine thumped home from 12 yards to seal a gripping win for Juventus.
Key Opta stats:
- Paulo Dybala has scored 12 penalties from 12 taken in Serie A.
- Juventus have won their last 31 Serie A home games.
- Gianluigi Donnarumma is the only goalkeeper to have made at least nine saves in two different games this season in Serie A (today and against Lazio on February).