Laidlaw, who scored 26 of Scotland's points, crossed in the 74th minute and converted it to leave his team 10 points clear.
There was still time for Samoa to hit back with its fourth try of a pulsating match -- Motu Matu'u going over for a converted effort --but Scotland ran down the clock to score a nail biting victory.
It left coach Vern Cotter's team an unassailable six points clear of Japan, which plays its final Pool B against the United States Sunday.
South Africa, sensationally beaten by the Japanese Cherry Blossoms in the opening match, went through at the top of the group with Scotland in second place.
Long suffering Scottish sports fans, who packed the St James' Park ground of Newcastle United, feared for much of the match that its rugby team would go the way of its football team, who missed out on the chance of Euro 2016 qualification in agonizing fashion during the week.
Samoa, so disappointing for much of the tournament, found revived energy to run in three first half tries to lead 26-23 at the break, the points tally a record for the opening half in a World Cup match.
Tusi Pisi, Manu Leiataua and Rey Lee-Lo crossed for the rampant Pacific Islanders while Tommy Seymour and John Hardie went over for the Scots.
Laidlaw's kicking kept Scotland in touch and his boot took his team ahead in a tighter second half.
Leading by three points, he then dashed over for a superb try that ultimately was to seal a last eight spot and a clash with Australia, which topped Pool A after beating Wales 15-6 in a later match Saturday.
Laidlaw admitted that his team had done done it the hard way.
"We did our best at times to give it away but credit to the boys who stuck at it," he told BBC Sport.
"This is huge for us and we are absolutely delighted to get over the line today."
Japan, which has lit up the tournament, but crucially lost its second match to Scotland, was hoping for a Samoa victory or a draw to leave it with a chance in the final game against the United States to seal a last eight place for the first time in its history.
Australia's win in a tense encounter at Twickenham was sealed by five penalties from Bernard Foley, the Wallabies surviving intense late Welsh pressure when down to 13 men to preserve its lead.
Wales will play South Africa next Saturday in its bid to reach the semifinals. Meanwhile, host England signed off its campaign with a 10-try 60-3 win over Uruguay with veteran No.8 Nick Easter and Jack Nowell scoring try hat-tricks, but earlier defeats to Wales and Australia had led to elimination.