The American striker netted early in each half as the Dons took command at the midway stage of the Europa Conference League third qualifying round.
The Dons made a flying start, converting from two corners inside 11 minutes through Ramirez and Lewis Ferguson.
They were undone by two long, diagonal balls as the home side went in at half-time on level terms after a goal from Gisli Eyjolffsson and an Arni Vilhjalmsson penalty.
But Ramirez netted his fourth goal for Aberdeen in the 49th minute of his fourth game for the Dons.
The United States international had taken less than three minutes to open the scoring following a well-worked corner. The striker peeled off to meet Calvin Ramsay's low delivery and fired home.
Ramirez soon latched on to a ball over the top from Jay Emmanuel-Thomas and powered a first-time effort that was pushed over the bar.
The Dons doubled their lead from the resulting corner when Ferguson rose well to head into the top corner from eight yards.
The home side soon pulled one back in the 16th minute. Ross McCrorie was outmuscled after a long ball bounced into the box and he brought down his man. But the grounded striker managed to knock the ball across goal for Eyjolffsson to get in front of Jack MacKenzie and net before the referee could blow for a penalty.
Jonny Hayes was too high with a long-range effort with the home goalkeeper stranded and Funso Ojo had a decent effort saved, but Aberdeen were caught out again two minutes before the break.
Ramsay slipped after a ball down the left was knocked into the Dons box and Andrew Considine made a rash challenge on Vilhjalmsson, who picked himself up and converted the spot-kick.
Aberdeen manager Stephen Glass made a triple substitution at the break with Declan Gallagher, Connor McLennan and Dylan McGeouch coming on.
The changes paid instant dividends as McLennan took down a long ball and squared for Ramirez to sweep home.
The hosts lost their discipline for a spell and Vilhjalmsson was fortunate to escape a second yellow card in five minutes for a blatant trip on Ramsay.
Aberdeen managed the second half well and Ramirez saw a header saved as he looked for his hat-trick.