The Astana rider prevailed with a late burst at the end of the 162.5km stage from Mentougou to the Badaling Great Wall.
Matthieu Ladagnous (FDJ), Johnny Hoogerland and Pim Ligthart (Vacansoleil-DCM), Mikel Nieve (Euskaltel-Euskadi) (EUS), Andriy Grivko (Astana), George Bennett (Radioshack Nissan Trek) and Christian Meier (Orica-GreenEDGE) escaped after the first climb of the day.
Their lead had swelled to 4:35 by the time they reached the third climb of the day, a category one ascent after 68.5km.
But the peloton whittled down that advantage and the escape group were caught inside the final 10km before a flurry of attacks on the third category climb to the finish.
Sylvain Georges (Ag2R) and Igor Anton (Euskaltel-Euskadi) had a burst before the Norwegian made what seemed a decisive move inside the final 3km.
But Team Sky's World Road Championship silver medallist tied up dramatically in the final 50m and saw the Italian and Ireland's Dan Martin (Garmin-Sharp) beat him to the line.
Gavazzi said: “I am delighted with the victory, which I have been chasing for the whole of this year. I was desperate to end the season well, this is my first year at Astana and I wanted to repay the faith of this team, which has always believed in me.”
Tony Martin retained the overall leader's jersey and is 40 seconds ahead of Gavazzi on GC.
All 18 WorldTour teams and the Chinese national team line up in the second edition of the five-day race.
- Johnny Hoogerland