FIFA World Cup Qualifying: Macedonia 1 Scotland 2
The Watford winger was the best player on the pitch in his first international start, and gave Scotland a deserved lead in the 59th minute.
The visitors had dominated the first half and were well worth their lead, but they looked like only getting a draw when Jovan Kostovski netted with seven minutes to play for Macedonia.
There was still time for the Scots to win it, though, as an 88th-minute free-kick from Shaun Maloney curled into the top corner.
Macedonia coach Chedomir Janevski made four changes to the side that beat Wales 2-1 on Friday, with Barcelona youngster David Babunski and attacker Adis Jahovic among the inclusions.
Anya made his first start for Scotland, who also brought in Barry Bannan and Steven Naismith in place of James Forrest, Leigh Griffiths and the suspended Robert Snodgrass.
Gordon Strachan's decision to include Anya looked a wise one, with Scotland dominating the first-half play in Skopje.
The pace and trickery of Anya caused Macedonia several problems, and he created the first chance of the game, crossing for Naismith, who could only head over.
The pair should have linked up again moments later, but Naismith agonisingly failed to get anything on a terrific cut-back.
The chances kept coming for Scotland, as Scott Brown was denied by a good save from Macedonia goalkeeper Tomislav Pacovski, while Anya had a late chance of his own, only to see his curling effort tipped over.
Scotland were nearly made to pay for their profligacy on the stroke of half-time, but Jahovic wasted a good chance.
Jahovic initially ignored Goran Pandev, who was waiting for a cut-back, before firing into the side netting, as the two sides went to the break on level terms.
Macedonia were improved in the second half, and saw much more of the ball, but Scotland - who were forced to substitute goalkeeper David Marshall at half-time with a hip injury - were still more threatening going forward.
Anya went close again with a curling effort, before the 25-year-old broke the deadlock in the 59th minute, racing on to a through ball from Brown.
Anya's shot had to be perfect, given the angle, and that it was, as his first-time finish nestled into the far corner.
Macedonia pressed for an equaliser, with substitute goalkeeper Matt Gilks making good saves to deny Aleksandar Trajkovski and Pandev as the hosts gathered momentum.
And they were lucky to have a penalty appeal turned down when Pandev fell under the attention of Brown.
Macedonia's pressure eventually told, as Pandev chipped a wonderful through-ball into the path of Kostovski, who finished well past Gilks.
But just as the hosts thought they had won a point, Scotland grabbed a dramatic late winner.
Maloney was the scorer, curling a brilliant free-kick into the top corner to give Scotland a deserved victory.