A last-gasp goal saw Rotherham United win the battle of the League One play-off contenders after a second half of total domination at AESSEAL New York Stadium.
The Millers bossed proceedings after the break but couldn't break down a Portsmouth side managed by their former boss, Kenny Jackett.
But they never stopped pressing and were rewarded in time added on when Joe Mattock popped up at the back post to head home substitute Michael Smith's cross.
Delirious home fans mocked Jackett after a thoroughly deserved victory which saw their team move up to seventh in the table and Pompey, who had defended heroically, drop to ninth.
After a cagey first half, Rotherham came tearing out of the blocks at the start of the second period and pinned the visitors in their own territory.
Will Vaulks' header from Anthony Forde's corner hit teammate Jerry Yates on the Pompey line and Vaulks' follow-up shot was kept out. Forde swung in another corner and Richard Wood poked wide at the back post.
Semi Ajayi had a shot blocked and David Ball turned a half-chance over the bar.
All this before the 60th minute, when Portsmouth finally broke out and Matt Kennedy fired over.
Back came the Millers, with Smith, making his home debut, seeing his shot blocked and then Ajayi being foiled by heroic defending for the second time.
Smith made a big impact and he was the provider in the 92nd minute when Mattock stole in for the glory.
In a closely-contested first half, there had been few chances at either end.
Rotherham goalkeeper Marek Rodak saved a 10th-minute Jamal Lowe shot and a Brett Pitman header just before the half-hour mark.
The Millers' best moment came in the 32nd minute when Ball turned and tried his luck from 20 yards only to see his effort deflected over for a corner.
It all changed after the interval, and that's eight games unbeaten now for manager Paul Warne and his men.
Rotherham United (4-4-2): Rodak; Emmanuel, Ajayi, Wood, Mattock; Forde (Taylor 83), Towell, Vaulks, Williams (Newell 65), Yates (Smith 65), Ball. Subs not used: Price, Cummings, Ihiekwe, Clarke-Harris.
Portsmouth (4-2-3-1): McGee;Thompson, Burgess, Clarke, Deslandes (Ronan 66); Close, Donohue; Lowe, Naismith, Kennedy; Pitman (Hawkins 66). Subs not used: Bass,Chaplin, Bennett, May, Widdrington.
Goals: Mattock 90+2 (Rotherham).
Referee: Robert Jones (Merseyside).
Attendance: 9,129 (1,471).