The Italy international scored his second goal of the game in the dying seconds as the visitors from Bergamo consigned Walter Mazzarri's men to a first defeat in six games
In a result that extends Atalanta's winning run to four Serie A games, the once-capped Italy international scored twice, with his decisive goal coming after withstanding a second-half barrage from Inter.
However, Inter's profligacy and Bonaventura's double proved crucial as the hosts missed the chance to move ahead of fourth-placed Fiorentina, who make the trip to Napoli later on Sunday.
After an entertaining start that saw visiting captain German Denis head against the crossbar, the opening two goals came within the space of two late first-half minutes.
Expert finishes from Bonaventura and Mauro Icardi ensured the sides went in level at the break before Inter twice struck the woodwork early in the second half.
Inter, though, failed to make the most of their chances and Bonaventura made them pay - heading home in the 90th minute to extend Inter's winless run against Atalanta to six matches.
With Walter Mazzarri's Inter going in search of a third straight victory, Hernanes played in Fredy Guarin for the game's first opportunity - the Colombian placing an effort marginally wide of Andrea Consigli's left-hand post.
The two combined again shortly after, but this time Guarin opted for power, as he fired over the crossbar.
Samir Handanovic was then required to keep out powerful efforts from Guglielmo Stendardo and Luca Cigarini as he demonstrated some of the form that had seen Inter keep clean sheets in their previous three outings.
Guarin's third effort stung the palms of Consigli before Icardi failed to provide a cutback for Rodrigo Palacio when played in behind the Atalanta defence.
Bonaventura's long-range strike dipped too late to threaten Handanovic before he eventually found the net at the third attempt after 35 minutes.
Following a quick break, Bonaventura made the most of Denis' decoy run to create space before firing past Handanovic.
However, Atalanta's joy was shortlived, as a minute later Icardi collected Guarin's slipped pass before cutting inside his marker and firing home the equaliser to restore parity nine minutes before the break.
As in the first half, Inter began on the front foot after the interval with Guarin at the centre of their attacking threat - firing a shot from distance that clipped the crossbar and went over.
Palacio was then denied by the post as he glanced Jonathan's cross over the helpless Consigli as Inter continued to pile on pressure.
However, Stefano Colantuono's charges secured a dramatic late win thanks to Bonaventura's fifth league goal of the season as Inter's European aspirations were dealt a blow.