The 32-year-old legspinner Zahid Mahmood picked up 3-40 in his debut game and had reduced South Africa to 65-7 before Miller's clean hitting powered South Africa to a total of 164-8. Miller hit five fours and seven sixes in his unbeaten knock.
South Africa's Tabraiz Shamsi grabbed 4-25 in a game dominated by spinners, but Pakistan's lower order hung in to reach 169-6 with eight balls to spare and record its 100th win in a Twenty20 international.
Hasan Ali (20 not out) raised the victory with two sixes and a four against Andile Phehlukwayo as seamers again found it difficult to grip the wet ball because of dew.
“Credit must be given to David Miller for playing an outstanding innings and making the match interesting,” Pakistan captain Babar Azam said.
“We told the players to play fearless cricket and that's why we finished on the right side.”
Babar top-scored for his side with 44 off 30 balls.
Pakistan beat South Africa 2-0 in the test series before completing the double by handing the Proteas its first defeat in a T20 series in Asia.
Earlier, Babar won the all-important toss in the winner-take-all game and his ploy of adding an extra spinner paid dividends.
South Africa ran into early trouble in the batting powerplay when leftarm spinner Mohammad Nawaz removed in-form Reeza Hendricks and Jon-Jon Smuts in his first two overs.
Pite van Biljon (16) struck three successive boundaries in Hasan's first over before he was undone by the fast bowler's slower delivery as South Africa slipped to 41-3 in six overs.
Mahmood, one of three changes for Pakistan, could have got three wickets in his first over had an lbw decision against Phehlukwayo not been overturned.
He baffled the Proteas with his legspinners and sharp googlies as captain Heinrich Klaasen top- edged a sweep for a duck and Janneman Malan (27) was trapped lbw off the back foot.
But Miller added 41 runs with Bjorn Fortuin (10) before cutting loose in the last four overs to lift South Africa's total.
Miller, the veteran of 81 T20s, provided the perfect finish when he smashed seamer Faheem Ashraf for four sixes in the last over which went for 25 runs.
Player of the series, wicketkeeper-batsman Mohammad Rizwan (42), and Haider Ali (15) provided Pakistan with a brisk start of 51 off 37 balls before Shamsi removed both batsmen in his first two overs.
Babar, who scored 0 and 5 in the previous two matches, demoted himself to No. 3 and held the innings together before Shami returned and claimed the wickets of Hussain Talat and Asif Ali.
Inbetween Shami's strike, Babar was clean bowled by Dwaine Pretorius which left Pakistan struggling at 117-5 in the 15th over.
However, Nawaz (18 not out) and Hasan got the home team over the line in the 19th over and Pakistan became the first team to complete a century of victories in Twenty20 internationals.
“We started with some cowboy cricket and I take full responsibility for that collapse,” said Klaasen.
“We are looking for a specific way to play … we just have to keep fighting and it was a good learning curve for the boys.”
For in-depth, objective and more importantly balanced journalism, Click here to subscribe to Outlook Magazine