Scrumhalf Danny Care scored the winning try seven minutes from time to spare England's blushes and complete a 18-17 victory over superb Samoa in their Rugby World Cup Pool D clash on Saturday in Lille.
Two tries from winger Nigel Ah-Wong had Samoa leading deep into the match, but their dreams of a first win over England were ended by poor discipline as they lost centre Tumua Manu to a yellow card and conceded repeated penalties that gave England the territory they needed.
England finished on 18 points. Argentina and Japan, both on nine, meet tomorrow in a shootout for a quarterfinal place. Samoa ended on seven, ahead of Chile on zero.
England are likely to meet Fiji in Marseille next week and will need to improve considerably to avoid losing to them again, having done so for the first time at Twickenham in August.
A performance littered with errors was summed up by captain Farrell becoming the first player at the tournament to be timed out by the shot clock as he exceeded the 60-second limit for a straightforward penalty with England trailing by six points.
"It was scrappy, it did not feel like the best from us," said Farrell. "All credit to Samoa and how they came out and got at us, it was tough to deal with at times and we did not deal with it discipline-wise and with mistakes. But I'm happy we found a way to win."
It had started well for England who struck after nine minutes with one of their best tries of the tournament. A fizzing pass by Farrell sent Freddie Steward and Manu Tuilagi clear before lock Ollie Chessum as an unlikely winger finished it off.
Farrell missed the conversion but landed a penalty to overtake Jonny Wilkinson as England's leading scorer, with 1,181 points and give England an 8-0 lead.
Samoa hit back quickly, working Ah-Wong over in the corner for only the second try England have conceded at the tournament.
That soon became three as Danny Toala launched a superb crossfield kick that Ah-Wong collected and then showed amazing dexterity to touch down as he flew beyond the in-goal zone.
England were wretched in thought and deed, and a poor kick by Alex Mitchell appeared to gift Duncan Paia'aua a third try only for the TMO to spot a knock-on and rule it out.
It was a lucky escape for England, who were fortunate to reach halftime only 14-8 down.
Samoa, seeking their first win over England at the ninth attempt, had the slimmest chance of reaching the quarter-finals but knew victory would have given them a fighting opportunity of securing automatic qualification for the 2027 tournament, and it looked on when another penalty put them 17-8 ahead.
England coach Steve Borthwick acted after 51 minutes, bringing Marcus Smith on for George Ford, with Farrell moving to flyhalf.
The 2019 runners-up quickly regained control, though tries by Chessum and Joe Marchant were ruled out. Farrell landed a penalty but, from right in front of the posts, was timed out with another.
A tiring Samoa had Manu sin-binned for an illegal aerial challenge and Care darted over for a try that Farrell converted for a one-point lead.
Samoa had hardly touched the ball in but came agonisingly close to winning it in the final minute with a sparkling attack that was foiled metres short by a tackle from Care.
England had secured top spot in Pool D but advance with a clean sweep of four wins.