Out-half Rainey kicked three first half penalties and Potts scored his try to leave the Irish 14-8 ahead at the interval.
They scored a superb second try in the 74th minute, O'Brien finishing off a move that saw the ball go through half a dozen pair of hands before O'Brien touched down. But minutes before the final whistle the Scots struck back with their second try of the game.
It was a thoroughly effecient display by the Irish against a much bigger Scotland side and when the Irish were asked to defend they did so with a high degree of courage and resolve.
They are now left with a game against Argentina - who lost today 24-18 to Wales - and the objective here is to win and gain a bonus point. The game will be played in Iffley Road next Saturday (6pm).