Hammarby made the short trip to Solna knowing a fourth win in a row would take them to just three points behind leaders Sirius, though that would not be easy against an AIK side chasing Europe and a third win in a row.
It was the away side who went in front with 13 minutes on the clock - Montader Madjed's low centre was turned away as far as Frank Adjei Jr at the edge of the box, and his deflected strike found its way through the crowd and into the net.
But AIK were level again before the Hammarby celebrations had died down, as they attacked down the left and Kevin Filling received a neat ball inside before squaring across the face of goal for Linus Carlstrand to score at the far post.
Midway through the first half, Madjed was fouled clumsily by Lukas Bergquist inside the area, but Kristoffer Nordfeldt not only saved Paulos Abraham's penalty, but got back up to deny Victor Lind on the rebound.
Nordfeldt made another superb save to deny Abraham again soon after, but in added time the Hammarby forward finally got the better of the goalkeeper, whose sloppy pass was pounced on by Bajen, and Lind slipped the ball through and this time Abraham curled the ball home.
The battle between the two had another flashpoint midway through the second half, as Nordfeldt's reaction stop denied Abraham a brace, and that proved vital, as four minutes later Filling was again the provider, this time providing a low cross from the right for Axel Kouame to sweep past Warner Hahn.
And with less than eight minutes of the 90 to play, AIK went ahead for the first time with a goal worthy of winning such a game - Ladji Camara's cross took a deflection, but that only made it drop perfectly for Sixten Gustafsson, who caught the volley sweetly with his right foot, arrowing the ball into the bottom corner.
Another victory for Gnaget takes them to fifth and 31 points, level with third-placed Elfsborg, while Hammarby have a five-point cushion over the chasing pack despite a first league loss since before the summer break.
The two residents of Gamla Ullevi met for what was Goteborg's home fixture, and unlike the reverse, this one concluded on schedule and Goteborg took the points to move seven points clear of the bottom three, while Orgryte remain second-bottom, five points from certian safety.
The only two efforts on goal in a tame first half belonged to the home side, who then took a deserved lead just past the hour mark when a Tobias Heintz corner was nodded in at the near post by Hjortur Hermannsson.
William Hofvander and Noah Christoffersson both had chances to get something out of the game, but OIS fell to a third defeat in four, with their only point in that run coming against Halmstad, the only side below them. Goteborg return to winning ways after two without victory, and climb to 11th place.
