The Serie A team appeared to be coasting in the round-of-16 first-leg tie when Cengiz Under put them ahead with his fifth goal in four games four minutes before halftime.
Yet as the temperature dipped towards minus-nine Celsius, Argentine striker Ferreyra took advantage of poor Roma defending to score with an expertly-taken goal in the 52nd minute.
That turned the game on its head and it was no surprise when Brazilian midfielder Fred curled in a free kick off the underside of the crossbar to stun the visitors in the 71st minute.
Shakhtar, the first team to beat English Premier League leaders Manchester City this season, began with six South American-born players in their lineup, though one of them, Marlos, now plays for Ukraine.
The Pitmen, playing only their second competitive game since a two-month winter break, were on the back foot in the first half and goalkeeper Andriy Pyatov made a double save from Edin Dzeko and Federico Fazio from one of several Roma corners.
Dzeko wasted another attack with a tame shot at Pyatov but made amends by setting up Roma’s goal in the 41st minute.
The Bosnian threaded a clever ball inside Ismaily to Under and, although Pyatov got a hand to the Turk’s shot, he could not prevent it ending up in the net.
The Italian side looked comfortable after the break, as well, but the game turned in the 52nd minute when Shakhtar scored out of the blue.
Yaroslav Rakitskiy played a long ball out of defence which Alessandro Florenzi lunged at but failed to cut out, allowing Ferrerya to break away.
The Argentine took his chance with aplomb, cutting inside Kostas Manolas to slot the ball past Roma keeper Alisson.
Shakhtar took control and Alisson made superb saves from Marlos and Taison before he was beaten by a brilliant free kick from fellow Brazilian Fred, who sent a looping shot over the wall and in off the crossbar.
Yet in stoppage time Alisson made a save to keep out another Ferreyra effort, which could yet prove crucial.