The narrow victory at Somerset's headquarters saw South Africa level the three-match series at 1-1 as bounced back from a nine-wicket defeat by England at Southampton two days earlier to set-up a winner-takes-all clash in Cardiff on Sunday.
England were on course for an unbeatable 2-0 lead while Roy (67) and Jonny Bairstow (47) shared a second-wicket stand of 110.
But when Roy was given out obstructing the field -- the first time this had happened in a T20 international -- the innings fell away.
A target of 12 off the last over became four off the last ball after Liam Dawson hit Andile Phehlukwayo for a boundary.
More From This Section
But he could not repeat the trick and South Africa had a morale-boosting victory to follow their first-round exit at the 50-over Champions Trophy, with this win achieved despite the absence of coach Russell Domingo, who had flown home after his mother was involved in a traffic accident.
Bairstow fell first, chipping man-of-the-match Chris Morris (two for 18) to mid-on. And then came the turning point.
Roy veered dramatically off a straight course, with the result he placed himself between the incoming throw from Phehlukwayo, which hit him on the heel, and the stumps.
South Africa appealed and, after on-field umpires Rob Bailey and Michael Gough referred the decision, Roy was given out by TV umpire Tim Robinson, the former England opening batsman.
=======================
Roy was clearly aghast but Morgan insisted it had been a "50-50 call".
"Everyone in the changing room thought it could go either way, so it's not massively controversial," Morgan told reporters. You can see why the umpires gave him out."
But England all-rounder Ben Stokes, who was given out obstructing the field in a one-day international against Australia at Lord's two years ago when he reacted to a shy at the stumps from bowler, Mitchell Starc by sticking out a glove, was unimpressed.
"Can't believe that @JasonRoy20 was given out in that manner today," Stokes, rested from this match, tweeted before continuing "embarrassment is the only word that can be associated with the decision."
England still had batting to come after Roy's exit. But Somerset 'old boy' Jos Buttler, now at Lancashire, was yorked by Phehlukwayo for 10 and Morgan (six) was well caught in the gloom by de Villiers.
England, who had been 133 for two at the start of the 16th over, lost four wickets for 34 runs before finishing on 171 for six.
Earlier, Cape Town-born Tom Curran, a Surrey team-mate of Roy, marked his England debut with an impressive three for 33 in his maximum allowed four overs.
Curran, the son of the late former Zimbabwe international Kevin Curran, struck with just his second ball in international cricket when Reeza Hendricks bottom-edged a pull into his stumps.
But fellow opener Jon-Jon Smuts made a brisk 45 with star batsman de Villiers, as he so often does, upping the tempo further with three sixes in his 20-ball innings.
They included an extraordinary sweep off one knee against left-arm paceman David Willey that flew into the River Tone before he was dismissed next ball.