The Scots were on the brink of winning their first Test in eight matches against France when New Zealand referee Chris Pollock awarded a debatable penalty in front of the posts as the ball came out from a ruck.
Replacement Jean-Marc Doussain made sure of the kick and there was barely any time left for Scotland to mount a comeback.
Victory -- France's first away from home in the Six Nations since winning at Murrayfield two years ago -- left Philippe Saint-Andre's side in with a shout of a winner-takes-all title clash with Ireland in Paris next week.
"We take the win, I think," Saint-Andre told the BBC as he acknowledged France's good fortune.
"Fair play to Scotland, they play very well with a lot of spirit. They scored two good tries. Our discipline was good and at the end we managed to win but I can't say it was our best game.
"But that is three wins in four and we'll prepare for a big game against Ireland."
An entertaining first half ended with Scotland 14-9 in front after Stuart Hogg and Tommy Seymour scored tries converted by Greig Laidlaw, with recalled scrum-half Maxime Machenaud kicking three penalties for the visitors.
France wing Yoann Huget's converted intercept try early in the second half saw the French go 16-14 in front and threatened to knock the wind out of Scotland's sails.
But with fly-half Duncan Weir, whose last minute drop-goal secured a 21-20 win away to Italy, landing a key penalty after throwing the poor pass that led to Huget's try, Scotland had a one-point lead heading into the final quarter.
Impressive Scotland No 8 David Denton made no attempt to hide his anguish, saying: "This is one of most disappointing days I've had in a Scotland jersey.
"We were very unlucky at the end there. We did really well, the front row in particular, against a French side who came here to beat us up at the set piece but we dominated the game."
Scotland coach Scott Johnson recalled captain Kelly Brown in one of three changes to the pack.
Brown replaced Glasgow's Chris Fusaro, while Geoff Cross and Denton recalled as well.
France kicked-off with a side showing seven changes to the one thrashed 26-7 by champions Wales last time out.
The very first scrum of the match saw France force a penalty which Machenaud kicked.
Eight minutes later good work by centres Maxime Mermoz and Mathieu Bastareaud took France to within sight of the try-line and Scotland were fortunate not to be a man down when they deliberately killed the ball in front of their posts.
Machenaud made no mistake and France were 6-0 in front.
But two minutes later Scotland took the lead. Laidlaw put up a clever high kick over the try-line which Huget failed to catch under pressure from Scotland counterpart Sean Lamont.
But full-back Hogg, following up, touched down and Pollock, after consulting the television match official, awarded the try.
Another Machenaud penalty took France 9-7 in front only for Scotland, on a Murrayfield pitch still disfigured by a parasitic infection, to regain the lead with a well-worked try as centre Matt Scott's delightful inside pass released wing Seymour to score.
Shortly before half-time France full-back Brice Dulin ran the ball out from under his own posts only for skipper Pascal Pape to cut short an enterprising move with a knock-on.
There was still time for France to be awarded another penalty but this time Machenaud missed.
Scotland started the second half on the attack only for Huget to intercept a 'telegraphed' looping pass from Weir, intended for Dunbar, and sprint some 90 metres for a try under the posts.
Laidlaw missed with a 45-metre penalty before Weir took over kicking and his 42-metre attempt put Scotland 17-16 in front.
And with six minutes remaining, the Scottish front row won another scrum penalty only for Weir's 44-metre kick to lack both distance and direction before France's late breakthrough.