Another late goal, this time a drilled effort from Gillingham left back Danny Jackman, condemned Brentford to defeat on their travels again.
With less than three minutes remaining Jackman picked the ball up as the visitors failed to clear a long throw, skipped past a couple of challenges and lashed the ball past Stuart Nelson from the edge of the box.
It was harsh on Brentford who had taken the lead through Jo Kuffour six minutes in and hit the post and the crossbar in a second half they dominated but was enough to give Gillingham the win.
The Bees took the lead the first time they got into the Gillingham box with a goal out of nothing.
Nelson collected a Gillingham corner and immediately lashed the ball the length of the pitch finding Kuffour in behind the home defence.
The Bees' top-scorer lofted the ball over Romain Larrieu and into the back of the net.
The rest of the first half was generally forgettable with Gillingham on top but unable to create many clear cut chances though Garry Richards could have doubled the lead when he headed a Kuffour cross on to the top of the net.
Andrew Crofts headed wide when well placed, Danny Spiller bobbled a shot wide and just before the half hour the home side pulled level.
Felix Bastians curled in a free kick and Crofts made an unchallenged run to the near post to head home.
Nicky Southall had a header saved and lashed a shot across the face of goal before the break and Gary Mulligan missed the target with two efforts soon after the re-start.
But Brentford were soon on top, Andrew Frampton headed wide and when Charlie Ide skipped past Jackman, Larrieu blocked his vicious shot, the ball dropped to Neil Shipperley who contrived to knock the ball wide of the open goal.
Frampton blasted a shot wide and, when Gillingham failed to clear a Joe Keith free kick, substitute Lloyd Owusu headed an Ide cross against the post.
Michael Leary, Kuffour and Ide had shots blocked from inside the penalty box while Gillingham substitute Andy Pugh shot wide.
Kuffour fired narrowly over after a fine turn but the home side were starting to come back into the game.
Bastians shot over the bar after a good run, Ben Chorley headed wide and Southall also missed the target when well placed.
Spiller and Mulligan had shots well blocked and the latter headed over the bar when he should have done better, Bastians then fired wide.
Jackman fired the crucial goal soon after but Brentford could still have earned themselves a point.
A Nelson free kick dropped to John Mousinho 12 yards out and his toe-poked effort was tipped onto the crossbar by Larrieu to ensure Brentford again headed home with no points.
Gillingham: Larrieu; Tonge, Cox, Chorley, Jackman; Southall, Crofts, Spiller, Bastians (sub Easton 86 mins); McDonald (sub Pugh h/t), Mulligan
Subs (not used): Jack, Sancho, Ndumbu-Nsungu
Bookings: Larrieu (71 mins)
Brentford: Nelson; O'Connor, Richards, Frampton, Tillen; Ide, Mousinho, Leary, Keith (sub Taylor 78 mins); Kuffour, Shipperley (sub Owusu 60 mins)
Subs (not used): Abbey, Osborne, Pinault
Bookings: Richards (45 mins) (second of season), Kuffour (79 mins) (third of season)
Written by Chris Wickham