Alexei Miranchuk gave Lokomotiv the lead on the half-hour mark as the Russian team threatened to pull off one of the biggest upsets of the season in the competition. But Dybala levelled in the 77th minute and doubled his tally two minutes later to help Juventus keep pace with Atlético Madrid at the top of Group D.
"I'm very happy, I really needed two goals like this," said Dybala, who had only scored once this season. "It was a difficult game but tonight you could really see the level of experience of our team. We always remained calm until we finally scored."
There have been question marks over whether Dybala, Cristiano Ronaldo and Gonzalo Higuain can all play together but Juventus looked a better side in the second half after the latter came off the bench, and posed more of an attacking threat.
"Now we won and you all say that we can play together. But if we were losing, the opinions would have been completely different," Dybala said. "I just say that we need to keep working hard as we are doing. The coach has his own ideas and we fully trust him."
Atlético also left it late, with substitute Álvaro Morata scoring in the 78th to give the Spanish side a 1-0 home victory against Bayer Leverkusen. Lokomotiv is four points behind Juventus and Atlético.
Juventus started well and pinned Lokomotiv back in its own half but struggled to really test goalkeeper Guilherme. Leonardo Bonucci missed a good chance when he met a Miralem Pjanic free kick with a glancing header that went wide.
And Bonucci was immediately at fault at the other end as he misjudged a long ball, allowing Miranchuk to pick out an unmarked Joao Mario. His shot was parried by Juventus goalkeeper Wojciech Szczesny but the ball came out to Miranchuk, who thumped it into the top right corner.
Juventus did have the ball in the back of the net at the end of the first half but play had already been stopped for a foul by Cristiano Ronaldo on the goalkeeper and so Dybala's effort was ruled out.
Juventus coach Maurizio Sarri brought on Higuain at the start of the second half but it was more of the same from the hosts who dominated possession but couldn't find a way past the Russian team's backline.
They finally did when Juan Cuadrado found Dybala and the Argentina international curled a strike into the top left corner. And Dybala turned the match around completely two minutes later, firing in the rebound after Alex Sandro's powerful effort was parried by Guilherme.
"Of course, we are disappointed that we couldn't take anything out of what was a good game for us," Lokomotiv coach Yuri Semin said. "But it was logical — we didn't have enough strength in the end. I didn't make substitutions in the hope that we would survive the final push from Juve, but we didn't."
More AP soccer: https://apnews.com/Soccer and https://twitter.com/AP_Sports