But a stand of 129 between Vince, who made 102, and Gregory turned the tide.
Pakistan paceman Haris Rauf removed both batsmen in quick succession on his way to 4-65.
But England, to the delight of most of a sun-drenched crowd of 19,500, won with two overs to spare when Brydon Carse, who had earlier taken five wickets, drove Shaheen Shah Afridi for four.
"It's pleasing to make a contribution, this time last week I didn't expect to get this opportunity," said Vince, the player of the match. "I'm delighted."
Earlier, Pakistan captain Babar Azam returned to form with a superb ODI best 158 during the tourists' 331-9.
Together with Mohammad Rizwan (74) he shared a partnership of 179 -- the highest for any Pakistan wicket against England in an ODI -- after opener Imam-ul-Haq had made 56.
But from 292-2, Pakistan, significantly, lost seven wickets for 37 runs.
Fast bowler Carse checked Pakistan's progress with 5-61, his maiden five-wicket haul at this level.
"The boys' efforts, not just today but throughout the series, the guys who have turned out, has been fantastic," said England stand-in captain Ben Stokes.
"It has been a tough week, but we've managed to pull through."
Meanwhile, a disappointed Azam said: "We started well but we were sloppy in the field.”
"We will learn from our mistakes and hopefully not repeat them," he added ahead of a three-match T20 series against England.
Azam, the world's top-ranked ODI batsman, had been dismissed for nought and 19 by fast bowler Saqib Mahmood, the player of the series, as England enjoyed commanding nine-wicket and 52-run wins at Cardiff and Lord's respectively.
But he responded in style.
Despite being without their usual top order, England began their chase in bold fashion.
Phil Salt hit 16 off the first over of their reply courtesy of four fours off Afridi, whose 10 overs cost an expensive 78 runs, including a fine straight drive off the left-armer.
But Hasan Ali dismissed Dawid Malan for a duck for the second match in a row, with both teams unchanged from Lord's.
Salt's dashing 37 ended when Rauf struck first ball to have him caught at midwicket.
Pakistan should have dismissed Stokes for just seven when he hoisted Shadab Khan straight to fine leg only for Ali to drop a routine catch and knock the ball on for four.
Stokes was reprieved again off leg-spinner Khan on 18 when a drive to long-on was dropped by Sohaib Maqsood and deflected over the rope for another four.
But an elated Khan got Stokes for 32, wicketkeeper Rizwan holding an edged sweep.
Hampshire captain Vince, so often an England nearly man, batted in stylish fashion and brought up a 91-ball hundred when he pulled Ali for four.
Gregory struck four fours and a six in his fifty.
Earlier, Azam spent 14 balls on nought and went to fifty in a relatively sedate 72 balls.
But so long as he stayed in there was every chance he would increase his scoring rate, with a cut boundary off Mahmood taking him to a 104-ball hundred.
He was dropped on 126 when Carse failed to hold a tough chance at midwicket.
The 26-year-old Azam drove Carse through the covers for four and lofted leg-spinner Matt Parkinson for six, to the delight of Pakistan fans at Edgbaston.
Rizwan's fifty, off just 42 balls gave Pakistan valuable impetus.
His exit led to a flurry of wickets, with Azam out in the last over after facing 139 balls, including 14 fours and four sixes.