Pompey finished 2017 on a high as they battled from behind to beat Northampton and climb into the play-off places.
They started poorly, but moved through the gears after Chris Long had put the struggling visitors ahead.
Matty Kennedy and Oliver Hawkins both struck in the space of a few minutes just before the interval.
Hawkins added a second following the restart and it might have been a greater margin of victory without an impressive display from Matt Ingram between the sticks.
Kenny Jackett made three changes from the side that beat AFC Wimbledon on Boxing Day.
One of them was enforced, with Brandon Haunstrup suffering from a knock and being replaced at left-back by Dion Donohue.
Meanwhile, Jamal Lowe and Conor Chaplin both dropped to the bench to make way for Kennedy and Hawkins.
Pompey had a great chance to open the scoring early on when Brett Pitman slipped a pass through to Hawkins, but Ingram stuck out a foot to make the save.
But the hosts looked well below par for most of the first half, perhaps fatigued by the hectic festive schedule.
Northampton tried to make them pay and Luke McGee was forced to back-pedal when Sam Hoskins tried to lob him.
The keeper then got down quickly to his right to make the save when Matt Grimes had a snap-shot from 35 yards.
And a teasing Brendan Moloney delivery flew past both Matt Clarke and Christian Burgess, although Long was unable to make a connection at the far post.
Pompey were forced to make a substitution on 25 minutes when Danny Rose collected a bizarre injury.
A drop ball was called for after Nathan Thompson received treatment on the pitch and John-Joe O’Toole accidentally kicked the midfielder in the leg in the battle for possession.
He was switched for Adam May, leaving the hosts with an extremely youthful central midfield pairing.
The Cobblers then broke the deadlock when Close lost possession and O’Toole sent a through ball to Long, who coolly slotted the ball past McGee.
But that seemed to spark Pompey into life and they managed to score twice in four minutes to turn the match on its head.
It was a lovely finish from KENNEDY to level, with the winger cutting on to his right foot and drilling a low shot into the bottom corner.
And it was an even better effort from HAWKINS to give the Blues the lead, as the striker rose on the edge of the box to expertly steer a deep Burgess pass over Ingram and into the net.
Northampton Town 1
Gareth Evans had limped off injured just before the break and he was replaced by Lowe before the game restarted.
The hosts were not content with a narrow lead, though, and Kennedy curled a shot narrowly over at the start of the second half.
And Pompey did find themselves further ahead on 48 minutes, as Donohue sent a perfect cross to the far post, where HAWKINS showed plenty of desire to rise above the defence and head home.
It almost got even better after Pitman’s back-heel was blocked, but Close’s follow-up rattled the crossbar.
The Blues were rampant by this point and it was only a string of saves from the overworked Ingram that was limiting the damage.
He did well to keep out an angled Pitman drive before also getting down to save another Hawkins header.
The keeper was also at his best deny Kennedy, while Lowe should at least have found the target after being sent racing through on goal.
There was, unsurprisingly, a bit of a lull following such a frantic opening to the half, although it was still the hosts looking more likely to add to the scoring.
Burgess went close after racing into the box to meet Kennedy’s free-kick and head narrowly wide of the post.
There were to be no more goals, although Pompey had already done enough to secure the points and their place in the top six.
Pompey (4-2-3-1): McGee; Thompson, Burgess, Clark, Donohue; Close, Rose (May 29); Evans (Lowe 46), Pitman (c) (Chaplin 89), Kennedy; Hawkins
Goals: Kennedy 41, Hawkins 45, 48
Booked: Pitman, Kennedy
Subs not used: Bass, Casey, Bennett, Main
Northampton (4-1-2-1-2): Ingram; Moloney, Poole, Taylor, Buchanan (c); Grimes; Crooks, McGugan; O’Toole (Foley 59); Hoskins (Powell 64), Long (Richards 72)
Goals: Long 36
Subs not used: Cornell, Smith, McWilliams, Waters
Referee: Lee Swabey
Attendance: 18,539 (538 away fans)
Matty Kennedy scored early in the second half to ensure Pompey picked up all three points at Gillingham.
The winger converted after Curtis Main’s header had come back off the woodwork to give the large travelling army – and all those watching live on Sky Sports – plenty to cheer.
A one-goal advantage ensured it was a nervy finale at Priestfield, but the struggling hosts never really looked like claiming an equaliser.
Kenny Jackett made two changes from the side beaten by Oldham in Pompey’s last league outing.
Striker Main was handed a first league start in more than a year in place of the injured skipper Brett Pitman.
Drew Talbot dropped to the bench to make way for Kyle Bennett, with Oliver Hawkins continuing to be deployed as a makeshift centre-back.
Nathan Thompson – who went off against the Latics with concussion – was declared fit to feature at right-back, but the game came too soon for Christian Burgess.
The watching television audience might have been forgiven for reaching for their remote, as the game took a while to find its flow.
In fact, the most noteworthy moment in the opening stages was the continuing efforts of various Priestfield staff to replace a dislodged corner flag.
Kennedy tried his luck with a curling right-footed effort, but the ball flew safely into the arms of Gills keeper Tomas Holy.
A delightful delivery from the outside of Jamal Lowe’s boot caused some problems, with Josh Parker having to head clear.
It was Ben Close who had the first decent chance on 20 minutes, though, with Holy having to get down to deal with his low drilled effort.
And a dangerous centre from Bennett flashed across the face of goal, with none of his white-shirted team-mates able to get a touch.
But the hosts grew in confidence as the first half progressed and thought they should have won a penalty on 34 minutes.
Hawkins’ challenge sent Sean Clare tumbling to the ground, only for referee Christopher Sarginson to ignore the appeals.
Pompey won a trio of corners before the break and two of them were met by Matt Clarke, but the defender sent both wide of the target.
It was Gillingham who ended stronger, though, and Parker volleyed narrowly past the post after being picked out by Lee Martin.
Pompey came tearing out of the traps at the start of the second half and were ahead after just 26 seconds.
Thompson whipped a cross in from the right and when Main’s header came back off the post, KENNEDY was waiting to stroke home the loose ball.
And Thompson might have added a second, with a cross that drifted towards goal and dipped narrowly over.
It was the visitors looking more likely to add to the scoring and a long-range attempt from Kennedy was not too far off target.
Hawkins then met another Kennedy corner, although his header lacked enough power to trouble Holy.
But Gillingham thought they had grabbed an equaliser when Finn O’Mara’s cross was converted by Parker.
The home fans leapt from their seats to celebrate before realising that the linesman had raised his flag for offside.
Jackett was forced to make his first change moments later, as Dion Donohue limped off to be replaced by Brandon Haunstrup.
Pompey had a chance to extend their lead when Bennett broke quickly on 74 minutes, but he took too long to find Lowe, whose effort was blocked.
Gareth Evans and Danny Rose were brought in for the closing stages, with Bennett and Close withdrawing to the bench.
But it was Clarke who almost grabbed a second goal for the Blues late on, diverting Kennedy’s free-kick inches past the post.
Gillingham (3-5-2): Holy; O’Hara, Ehmer, Nugent (Tucker 45); Parker, Hessenthaler, Martin (c) (List 57), Bingham, Ogilvie; Wilkinson, Clare (Oldaker 67)
Subs not used: Arnold, Simpson, Wagstaff, Nash
Pompey (4-2-3-1): McGee; Thompson, Hawkins, Clarke, Donohue (Haunstrup 67); O’Keefe (c), Close (Rose 83); Lowe, Bennett (Evans 83), Kennedy; Main
Goals: Kennedy 46
Booked: Clarke, Thompson
Subs not used: Bass, Talbot, Oxlade-Chamberlain, Naismith
Referee: Christopher Sarginson
Attendance: 8,163 (1,333 Pompey fans)
Pompey’s inconsistent start to the season continued as they were beaten 3-1 by Northampton at a sodden Sixfields Stadium.
The visitors were well below-par in the first half and trailed to a Chris Long strike and Matt Clarke’s unfortunate own-goal.
But they dominated after the break and Matty Kennedy deservedly pulled one back, with several more chances to level the game soon following.
A healthy travelling support were not able to celebrate a leveller, however, and Long netted again for the hosts to wrap up victory for the Cobblers.
Kenny Jackett made one enforced change from the side that won at AFC Wimbledon three days earlier.
Oliver Hawkins suffered a nasty head wound in that fixture and was replaced up front by Conor Chaplin.
A mixture of driving rain and strong winds made conditions difficult for both sets of players throughout the contest.
Pompey carved out a couple of half-chances in the early stages before Kennedy curled a 20-yard effort narrowly over the bar.
But it was the hosts who almost broke the deadlock on 15 minutes, with Matt Grimes’ free-kick causing confusion between Luke McGee and Clarke before eventually swinging out of play.
It was only a brief respite for the Blues, however, as the Cobblers did forge ahead just a few moments later.
Shaun McWilliams slipped a fine pass through to Long and although McGee came off his line to narrow the angle, the striker neatly slotted home.
Unfortunately, McWilliams’ evening was soon cut short, as he went down injured and had to be stretchered from the pitch.
That did not stop the Cobblers’ charge, though, and some poor defending allowed them to double their advantage on 32 minutes.
Grimes delivered a free-kick from wide on the right and no Pompey player was able to get it clear, with the helpless Clarke only able to turn the ball into his own net at the far post.
It seemed to stun the Blues into action and they had a few opportunities to reduce the deficit before the interval.
Northampton almost provided a helping hand when Ash Taylor diverted Jamal Lowe’s cross against his own post.
Stuart O’Keefe then tried a long-range effort deep into stoppage-time that Matt Ingram did well to tip over the bar.
Northampton Town 2
Pompey had been poor before the break, but whatever Jackett told them during the interval seemed to do the trick.
They came roaring out of the blocks and soon reduced the deficit when O’Keefe teed-up KENNEDY for a fine finish into the bottom corner.
Adam May then had an effort deflected over before Lowe arrived at the far post to head Damien McCrory’s cross just past the post.
The Blues kept pouring forward and Brett Pitman received the ball inside the box, only for some decent Cobblers defending to prevent him getting a shot away.
Lowe then had another excellent opportunity to draw the visitors level, as there was time for him to bring Kennedy’s cross under control before a wild shot that flew wide.
Jackett made his first switch of the evening just before the hour mark, as May made way for Ben Close in midfield.
Lowe seemed to be involved in everything that was happening and soon after being booked for a foul on Daniel Powell, his low centre was deflected into the arms of a grateful Ingram.
It was pretty much one-way traffic and when McCrory’s free-kick was only partially cleared, Kennedy sent the ball back into the box, where it was turned wide by Chaplin.
But rising hopes were dashed on 70 minutes when Northampton scored against the run of play to strengthen their advantage.
There was some good work on the right by Brendan Moloney and Crooks, with the latter’s cross flicked on by Alex Revell for Long to lash home his second of the night.
Pompey, to their credit, kept trying to get the ball into their opponents’ box, but the Cobblers were holding firm at the back.
They forged a decent opening late on, however, when McCrory whipped a fine free-kick into the box, where Christian Burgess’ header was kept out by Ingram.
And the keeper made an even better stop on 87 minutes, flinging himself to the right to palm clear O’Keefe’s cleanly-struck attempt and ensure there was no late drama.
Northampton (4-4-2): Ingram; Moloney, Taylor, Pierre, Buchanan (c); Crooks, McWilliams (Kasim 29), Grimes, Smith (Powell 56); Revell (Richards 78), Long
Goals: Long 18, 70, Clarke 32 (og)
Subs not used: Cornell, Barnett, Poole, Waters
Pompey (4-2-3-1): McGee; Thompson, Burgess, Clarke, McCrory; May (Close 57), O’Keefe; Lowe, Pitman (c), Kennedy; Chaplin
Goals: Kennedy 49
Booked: Thompson, Clarke, Lowe
Subs not used: Bass, Talbot, Donohue, Bennett, Naismith, Main
Referee: Darren Drysdale
Attendance: 5,855 (1,153 Pompey fans)
Loan : Cardiff City – Portsmouth