First blood went to the hosts via a Greig Laidlaw penalty. But Murray and Stockdale responded for the visitors who held a 12-10 lead at the pause.
Earls extended the advantage after half-time with Ireland's third try.
However their joy at the victory over may be qualified. Johnny Sexton, Ireland's world player of the year, left the field with an injury in the first-half.
He will be assessed to see if he is fit for their next fixture in Rome against Italy on 24 February.
"We have a lot of belief," said Ireland skipper Rory Best. "That was a really tough game. But we asked for a physical reaction after the loss to England and by and large we got that.
"It was two teams who went hard and we are very grateful to win."
Scotland next take on France in Paris on 23 February. "Any time you lose a Test match it is disappointing," said Scotland captain Greig Laidlaw. "We are frustrated and disappointed. But you have to give credit to them, they took their opportunities."