Petry and Tyler Toffoli scored, and Cayden Primeau made 21 saves in his second start for Montreal (23-18-9), which is fourth in the North, eight points ahead of the fifth-place Calgary Flames. The top four teams will qualify for the Stanley Cup Playoffs.
Tim Stützle and Thomas Chabot scored for Ottawa (19-27-5), which was eliminated from playoff contention.
"We knew Montreal needed those points and they need every single point they can for the rest of the season," Chabot said. "And we knew that they were going to come out hard, and obviously we had a little letdown there at the end, the last 13, 15, whatever minutes it is."
Petry scored at 8:12 of the third period to get the Canadiens within 2-1.
Toffoli's power-play goal tied it at 2-2 at 14:25. It came minutes after Nick Suzuki scored at 10:37, but Ottawa used a coach's challenge for goaltender interference and the call on the ice was overturned.
It was the third time the Canadiens have come back to win after trailing by multiple goals this season, and the second game in a row. They trailed 2-0 and 3-1 against the Winnipeg Jets on Friday before scoring four straight goals in a 5-3 win.
"I'm really happy for the kid, for sure," Canadiens coach Dominique Ducharme said of Caufield. "I mean, it's special to be scoring your first NHL goal in overtime, but I'm happy for the team too. You know, it's a big win. And we were resilient. We played with attitude and character, and that's something that we talked about in the last few days that we want to carry on. So I like the way we reacted and it was a happy ending for everyone."