Montoya, who started third, pulled away on a late restart from Ambrose, his biggest challenger all day, and beat Kurt Busch by 4.7 seconds in the 90-lap race around the 11-turn, 2.45-mile layout.
It was Montoya's second career victory, the other coming on NASCAR's other road course at Sonoma in 2007, 113 races ago. Ambrose was third, his third straight top-three finish at Watkins Glen, followed by AJ Allmendinger and polesitter Carl Edwards.
"It's about time," Montoya said. "We've lost a lot of them, gave away a lot of them. It gets frustrating, everybody fighting."
Jamie McMurray, Tony Stewart, Kyle Busch, Jeff Burton and Jeff Gordon rounded out the top 10.
It was the first career victory for Montoya's crew chief, Brian Pattie, whose call for four tires at the Brickyard 400 cost his driver a chance at victory.
"It's huge," Pattie said, fighting back tears. "I still want to win on an oval. He wants to prove his point. The Brickyard was my fault. Hope this makes up for it. Trophies mean a lot. It's pretty cool."
Ambrose, who won his third straight Nationwide race at The Glen on Saturday, was poised to capture his first Sprint Cup victory at Sonoma in June when things went awry. He stalled his No. 47 while leading under a late caution, was unable to keep pace, had to restart seventh when he couldn't get it refired, and finished sixth.
He seemed destined to finally break through, but the handling went away on the last set of tires and Kurt Busch slipped past him late.
"It hurts," Ambrose said. "It doesn't feel nice."
Montoya was able to pull away on every restart, but each time Ambrose reeled him back in. But when the race restarted for the final time with 15 laps remaining, Kurt Busch passed Ambrose as Montoya took off again, pulling away as Busch kept Ambrose at bay.
Ambrose got past Busch in the first turn of lap 77 and began the chase again as it became a two-car contest. This time, Ambrose was unable to cut into the lead as Montoya steadily pulled away, increasing his lead from 1.7 seconds to 4.2 seconds in a five-lap span.
Ambrose, who started 11th, steadily made his way up through the field after the green flag waved and was second on lap 24. Edwards took second from Ambrose on a restart a third of the way through the race after the first caution, but Ambrose came right back to retake the spot entering the first turn on the next lap and began stalking Montoya.
Montoya was hard on the brakes, often smoking the tires, as Ambrose stayed glued to his back bumper. Ambrose nearly touched Montoya on lap 39, but backed off. Both were side by side in the inner loop at the top of the high-speed esses on lap 40. Ambrose finally made the pass on the 41st lap in turn one, forcing Montoya onto the runoff area with an aggressive inside move.
After a mid-race caution for an accident, Ambrose led the field to green but lost three positions on the restart as Montoya regained the top spot with Kurt Busch and Allmendinger also slipping past Ambrose.
Ambrose passed Allmendinger again on the next lap, then sailed past Kurt Busch in turn one on lap 50 and began to chase Montoya for the second time.
Ambrose pulled back on Montoya's back bumper on lap 58 with Brad Keselowski fighting to stay on the lead lap as the two filled his rearview mirror with their final pit stop looming.
Both pitted together with 30 laps remaining and Montoya beat Ambrose out before a caution flew for debris.
Montoya held off Ambrose when the race restarted, but two laps later Stewart clipped Boris Said in the exit of turn one, a hard downhill right-hander, sending Said into the guardrail to bring out another caution.
That erased any worries about fuel in case of overtime, but as soon as the race restarted, Jimmie Johnson and Denny Hamlin were involved in a crash in turn 7 to bring out another caution. Johnson's No. 48 Chevy slammed a retaining wall and the front of Hamlin's No. 11 Toyota was crushed.
"He's driving a great race," Ambrose said of Montoya during the caution. "He's really hard to pass. It's going to be a big battle. I'm going to see if I can force him into a mistake. I just want to be clean until the end."
There were no mistakes this time as Montoya gave Earnhardt Ganassi racing just its third victory of the season.