Gillingham dropped out of the play-off places for the first time this season following a third straight home defeat.
The Gills weren’t short of goalscoring chances but slipped up against relegation-threatened Shrewsbury.
Sullay Kaikai put the visitors ahead but the Gills deservedly got back on level terms with a Cody McDonald blockbuster.
Andy Mangan fired the Shrews back in front early in the second half, Jake Hessenthaler made it 2-2 but Jean-Louis Akpa Akpro scored a winner late on.
The result extended Gillingham’s winless run to six games.
Gillingham had already seen Barnsley move above them into sixth before kick-off, after a goalless draw against Sheffield United in the lunchtime match.
Defeat left the Gills in seventh place with two games remaining.
Shrewsbury, struggling at the bottom end of League 1, were just as keen for a win as the Gills. Victory for them was a major boost to their survival hopes.
Boss Justin Edinburgh returned Cody McDonald to the starting XI, playing alongside Luke Norris in a 4-4-2 formation, as Bradley Dack returned to his familiar position behind the front two.
There wasn’t a lot wrong with the way Gillingham started the game, with McDonald hitting the top of the bar as early as the fifth minute from a Deji Oshilaja cross.
Visiting keeper Jayson Leutwiler was being kept busy, making saves from Dack and John Egan, but it was Shrewsbury who took the lead with a goal from nothing.
Kaikai picked up the ball 20 yards out and hit a hopeful shot that bounced in front of Gills keeper Stuart Nelson and hit the back of the net.
Gillingham rallied and Leutwiler had to tip a Dack free-kick over and save again from McDonald, but the game was all-square in the second minute of first-half stoppage-time. Dack laid the ball off from a free-kick and McDonald rammed the ball into the top corner.
It was McDonald’s fourth goal of the season, his last coming in the 2-2 draw at Shrewsbury in November.
He had another chance early in the second half, again from a free-kick laid off by Dack, but he slipped when taking the shot and the keeper saved.
Gillingham were back chasing the game with 56 minutes gone as Shrewsbury scored from a corner. Kaikai’s corner was headed back into the box and Mangan netted with an overhead kick.
Four minutes later the Gills were level again. Aaron Morris found Josh Wright and he in turn picked out Hessenthaler on the edge of the box, who let fly into the bottom corner.
Norris shot wide with 20 minutes left and McDonald forced a save from Leutwiler soon after.
Oshilaja also tried his luck from distance but was off target, as was Hessenthaler, with a shot that flew just wide.
Despite all of the pressure coming from the Gills, the visitors hit back on the counter to make it 3-2, exposing space left at the back as Edinburgh’s men searched for a winner. A curling effort from Akpa Akpro which was just out of Nelson’s reach was the clincher for the visitors.
Gillingham: Nelson, Garmston (Dickenson 62mins), Egan, Oshilaja, Ehmer, Wright, A Morris (Williams 78mins), Hessenthaler, Dack, McDonald (Donnelly 89mins), Norris. Subs not used: G Morris, Jackson, McGlashan, Osadebe.
Shrewsbury: Leutwiler, Sadler, Whitbread, Kaikai, Wesolowski, Grimmer, Ogogo, Mangan (Black 83mins), Knght-Percival, Hendry, Akpa Akpro. Subs not used: Halstead, Vaseell, Whalley, Clarke, Cole, Smith.
Attendance: 6,906 (205 away).