The visitors took the lead in an often scrappy contest when Oliver Hawkins headed home in the second half.
And there were opportunities to extend the advantage before Stuart Sinclair struck following a period of Pirates pressure.
It looked like the spoils were to be shared, only for Liam Sercombe to drill a winner in the dying moments.
Kenny Jackett made two enforced changes from the side that saw off Northampton on home soil at the weekend.
Danny Rose and Gareth Evans both limped off against the Cobblers, so in came Adam May and Jamal Lowe.
Pompey’s injury problems were clear from a look at the bench, with Theo Widdrington recalled from a loan spell with the Hawks and joining academy prospects Matt Casey and Dan Smith.
It was the hosts who looked brighter in the opening stages and Luke McGee got down well to deal with a long-range attempt from Billy Bodin.
But the Blues soon grew into the game and were enjoying plenty of possession, without being able to test Adam Smith between the sticks.
A couple of balls into the box had to be hacked to safety, while Lowe’s effort was deflected narrowly wide.
There was danger at the other end when Lee Brown sent a dangerous delivery into the mixer, only for Bodin to collide with Sinclair as they both tried to meet it.
It was certainly the hosts looking more fluent as the half progressed and May charged down Rory Gaffney’s strike, before Tom Broadbent’s surging run was halted by Christian Burgess.
Pompey were still trying to create chances of their own, however, and Smith had to keep out Brett Pitman’s drive at his near post following good work down the right from Nathan Thompson.
Matt Clarke then looked like he was about to convert Dion Donohue’s free-kick, only for the keeper to come off his line and punch clear.
It was a decent spell from Pompey and Joe Partington had to divert the ball behind when Pitman – given plenty of stick for his Bristol City connections – stretched to reach Thompson’s cross.
The action then swung back in Rovers’ favour, although pressing from the Blues back-line was leaving the home crowd frustrated.
Bristol Rovers 0
Pompey won an early corner once play restarted and Burgess sent a header looping narrowly over from Donohue’s delivery.
But it was Rovers who came close to breaking the deadlock on 51 minutes, as the ball pinged around the Blues box.
Bodin’s effort was kept out by the feet of McGee and when it was sent back into the area, Tom Nichols diverted it narrowly off target.
There was a melee in the opposite area on the hour mark, but when Pitman centred the ball, Chris Lines was well-placed to hack it clear.
And the visitors did forge ahead on 64 minutes, as a HAWKINS rose to meet May’s fine cross and guide a precision header past the desperate dive of Smith.
They came close to doubling their advantage, only for a Ben Close thunderbolt to be blocked by a Rovers shirt in a packed box.
And Matty Kennedy then did well to trick his way into space and flash a low shot narrowly past the post.
But Bodin came close to a leveller at the other end on 77 minutes, with a rising effort that McGee had to palm over the crossbar.
Rovers were piling on plenty of pressure in the closing stages and it finally paid off with a late leveller.
Bodin’s strike was saved by McGee, but he could not keep hold of the ball and Sinclair followed up to find the net.
And the Blues were left heartbroken when, in the 90th minute, a free-kick was played to Sercombe, who drilled a shot into the bottom corner.
Bristol Rovers (4-3-3): Smith; Partington, Lockyer (c), Broadbent (Sweeney 59), Brown; Sinclair, Clarke (Sercombe 74), Lines; Bodin, Nichols, Gaffney (Harrison 74)
Goals: Sinclair 84, Sercombe 90
Subs not used: Slocombe, Bola, Moore, Telford
Pompey (4-2-3-1): McGee; Thompson, Burgess, Clarke, Donohue; Close, May; Lowe (Bennett 90+2), Pitman (c) (Main 81), Kennedy; Hawkins
Goals: Hawkins 64
Subs not used: Bass, Casey, Widdrington, Smith, Chaplin
Referee: David Webb
Attendance: 10,014 (1,165 Pompey fans)