Media playback is not supported on this device
The hosts went into the match with confidence high after last week's victory over Italy but they were awful against Ireland before the break.
However, Ireland had only a Paddy Jackson penalty to show for all their possession and territorial advantage.
Wing Craig Gilroy did cross for the visitors shortly after the restart but four Greig Laidlaw penalties secured the win for the hosts.
On paper, it was a miraculous victory for Scotland - Ireland had 78% of possession and 80% of territory before the break - but the visitors only had themselves to blame for a string of missed opportunities.
For Scotland, it was their first back-to-back victory in the Six Nations since 2001 following their record win over Italy last week.
But for Ireland, it was the first time they have lost two Six Nations games in a row since 2008 and leaves head coach Declan Kidney's future in some doubt.
Ireland came into the match in some disarray, last week's defeat by England having ruled out Simon Zebo and Gordon D'Arcy for the tournament and Jonathan Sexton and Mike McCarthy out of the match with Scotland.
With Sexton injured, Kidney picked Ulster's Jackson at fly-half instead of the vastly experienced Ronan O'Gara and the 21-year-old's first touch was a nervy knock-on.
(provided by accenture)
Regardless, the visitors had the edge in the opening exchanges, with Ulster centre Luke Marshall, also on debut, wreaking havoc in the Scotland ranks.
First, Marshall scythed through the Scotland midfield and set Keith Earls free, only for the Munster wing to be tackled short of the line. And a couple of minutes later Marshall should have put Gilroy in for a try in the other corner after another clean break but butchered the pass.
Ireland continued to apply pressure and prop Ryan Grant was shown a yellow card for interfering with Laidlaw's run after 16 minutes, although Jackson missed the resulting penalty from out wide.
A minute before Grant's re-appearance Ireland had another clear-cut try-scoring opportunity but Earls decided to go on the outside when he had Brian O'Driscoll inside him and was bundled into touch by Sean Maitland.
With Scotland leaking penalties at the scrum and breakdown Ireland continued to batter away at them. But the first points did not come until the 35th minute, when Jackson slotted a penalty from in front of the posts.
Stuart Hogg's long-range penalty attempt came up short on the stroke of half-time but Scotland would have been mightily relieved to be only three points behind. Ireland, meanwhile, should have been over the hill and far away.
Media playback is not supported on this device
The second half started where the first half left off, with Ireland coming in waves. But Scotland's defence, which had hitherto been monumental, could hold out no longer and Gilroy pirouetted over for a try three minutes in.
However, two penalties from Laidlaw reduced the deficit to two points while two missed kicks by Jackson would have increased the visitors' concern. That concern would have turned to genuine fear when Laidlaw gave Scotland the lead with another three-pointer after Ireland collapsed a maul.
Entering the final quarter Scotland looked like the more vibrant side, while Ireland, feeling the need to take risks, began to make crucial mistakes.
O'Gara was introduced after 66 minutes but with Scotland content to kick for territory the Munster veteran was unable to make a mark.
Ireland camped out on Scotland's try-line for the final few minutes but Scotland's defence held firm, with the result confirmed when Marshall knocked-on.
Scotland: Hogg, Maitland, Lamont, Scott, Visser, Jackson, Laidlaw, Grant, Ford, Cross, Gray, Hamilton, Harley, Beattie, Brown.
Replacements: Weir for Jackson (60), Hall for Ford (45), Low for Cross (74), Kellock for Hamilton (72), Denton for Beattie (72).
Not Used: Welsh, Pyrgos, Evans.
Sin Bin: Grant (16).
Ireland: Kearney, Gilroy, O'Driscoll, L. Marshall, Earls, Jackson, Murray, Court, Best, Ross, O'Callaghan, Ryan, O'Mahony, Heaslip, O'Brien.
Replacements: Fitzgerald for Gilroy (60), O'Gara for Jackson (64), Reddan for Murray (70), Kilcoyne for Court (53), Toner for O'Callaghan (72), Henderson for O'Mahony (72).
Not Used: Cronin, Fitzpatrick.
Att: 67,006
Ref: Wayne Barnes (RFU).
Scotland recovered from a woeful first-half performance to overhaul Ireland and keep their Six Nations Championship hopes alive.