Ambrose started the last lap in third place behind Kyle Busch and Keselowski.
He grabbed second when Busch spun after Keselowski made contact with him. Ambrose then chased down Keselowski, bumped into the rear of his car, wrested the lead from him on the ninth turn and held off his last-gasp challenge for the win.
It was the second time in two years Keselowski has finished second to Ambrose at Watkins Glen.
Dale Earnhardt Jr. lost the Sprint Cup points lead to Johnson after a 28th-place finish.