Johnny Sexton knocked over a late penalty as Ireland survived a surge from Scotland to eke out a hectic Six Nations victory at Murrayfield.
A converted try from Hamish Watson brought the hosts level with five minutes remaining but Sexton held his nerve to kick the winning points.
Robbie Henshaw and Finn Russell traded unconventional first-half scores.
Soon after a Tadhg Beirne score, Ireland led 24-10 before Huw Jones began a comeback that fell just short.
A sixth successive win over Scotland lifts Ireland up to second in the table, although they go into their final match at home to England with no chance of winning the championship.
Scotland, who opened with a historic win at Twickenham, are stuck in fifth place, having lost three in a row in Edinburgh for the first time since March 2015.
Gregor Townsend's side had four weeks to stew over a careless one-point loss to Wales after the postponement of their visit to Paris and made a sluggish start.
Ireland were on the front foot straight away, with powerful carrying from their forwards, and Sexton was soon clipping over a simple penalty.
The Scottish line-out malfunctioned horribly and the first of six steals from eight throws resulted in the opening try as Sexton hoisted a cross-field kick into scoring zone.
Stuart Hogg and Chris Harris both went up against Keith Earls with no one able to gather and the ball popped loose for Henshaw to pounce on.
Sexton's conversion attempt from a tight angle clipped the post - that would be the veteran fly-half's only miss.
Scotland reduced the deficit with a Russell penalty but struggled to find any momentum because of the haphazard nature of their set-piece.
If there was a touch of fortune about the game's opening try, the second was downright freakish.
Hogg charged down a kick then managed to hack the ball on twice, with the first attempt coming off his own chin. Russell won the race to reach it but his touch with the boot seemed too heavy.
However, James Lowe, in his attempt to intercept only succeeded in patting the ball up in the air and it fell perfectly for Russell to gather and score before he added the extras.
Somehow the hosts were in front, although not for long.
Ireland snaffled yet another dreadful line-out and quickly hammered it forward to earn a penalty, which Sexton knocked over with ease and, on the cusp of half-time, Sexton was at it again thanks to an offside gift from Ali Price.
The second half was nine minutes old when Beirne crashed through for Ireland's second try. Sexton slotted the conversion and was soon adding another penalty, with Scotland second best at the breakdown.
The hosts were down by 14 points and looking rather lost before an exceptional score from Jones hauled them back into the mix.
Sam Johnson ate up ground with purpose and the ball was worked wide on the right for the replacement centre to motor onto, with his power and pace taking him away from the grasping hands of four opponents.
A glut of injuries meant a major reshuffle for the Scots but suddenly they were energised and battering away under the posts.
Duhan van der Merwe was almost in and kept a cool head to keep the ball alive, with Watson burrowing over from close range.
Hogg crashed over the extras and it was a level game with just a few minutes on the clock.
Ireland must have been sick after surrendering such a commanding lead but they summoned one more venture forward and when Ryan Baird charged down Price's kick, the home scrum-half was penalised for holding on, allowing Sexton the final word.
Sexton v Russell?
No contest.
Much of the pre-match narrative was of Russell snapping at the heels of Sexton for a British and Irish Lions place but the Irish captain was streets ahead, pinging over a tricky fifth penalty of the afternoon to seal victory.
Yes, Russell scored a try, but it came from some bizarre pinball. The Scotland number 10 sent a wild penalty attempt wide in the first half and blazed a kick to touch in the corner miles out on the full when Scotland were in need of a lift early in the second half.
He was removed on 62 minutes after a bang on the head, which will likely rule him out against Italy next week, and Scotland looked more dynamic with Hogg taking over at fly-half.
Man of the match - Tadhg Beirne
'Not my best strike'- reaction
Scotland captain Stuart Hogg: "Ireland were outstanding for 80 minutes and fully deserved the win.
"The frustrating thing for us is giving them 24 points in the first place. Credit to Ireland, they took their opportunities but for the second week in a row we've been ill-disciplined, allowed them easy field position and kind of killed ourselves at times."
Ireland captain Johnny Sexton: "I probably got a little bit lucky [with the winning kick] it was not my best strike - and it got there thankfully.
"We're just letting in soft tries, which is not acceptable at international level, and it is a little frustrating as we dominated the game. But, if we can finish second after a poor start to the Six Nations, we'll be happy."
Scotland: 15-Stuart Hogg (capt), 14-Sean Maitland, 13-Chris Harris, 12-Sam Johnson, 11-Duhan van der Merwe, 10-Finn Russell, 9-Ali Price; 1-Rory Sutherland, 2-George Turner, 3-WP Nel, 4-Scott Cummings, 5-Jonny Gray, 6-Jamie Ritchie, 7-Hamish Watson, 8-Matt Fagerson
Replacements: 16-David Cherry, 17-Jamie Bhatti, 18-Simon Berghan, 19-Grant Gilchrist, 20-Nick Haining, 21-Scott Steele, 22-Huw Jones, 23-Darcy Graham
Ireland: 15-Hugo Keenan, 14-Keith Earls, 13-Garry Ringrose, 12-Robbie Henshaw, 11-James Lowe, 10-Johnny Sexton (capt), 9-Jamison Gibson-Park; 1-Cian Healy, 2-Rob Herring, 3-Tadhg Furlong, 4-Iain Henderson, 5-James Ryan, 6- Tadhg Beirne, 7-Will Connors, 8-CJ Stander
Replacements: 16-Ronan Kelleher, 17-Dave Kilcoyne, 18-Andrew Porter, 19-Ryan Baird, 20-Jack Conan, 21-Conor Murray, 22-Billy Burns, 23-Jordan Larmour
Match officials
Referee: Romain Poite (France)
Touch judges: Mathieu Raynal (France) and Andrea Piardi (Italy)
TMO: Alex Ruiz (France)