The managerless Stags, third bottom in the Football League, grabbed two goals in 90 seconds to cap a thrilling second-half fightback as they looked to add the Lions to the scalps of Stoke City and Southampton in earlier rounds.
But then in the last minute, moments after Adam Rundle had almost grabbed a winner for Mansfield, Dave Livermore broke the home side's hearts.
A free-kick was cleared to the edge of the area and the midfielder hammered a first-time volley into the top corner to clinch a thrilling 3-2 victory.
Millwall, missing four regulars, had brought in former Scottish International Don Hutchison as they looked to avoid an upset. But a mistake by the experienced player almost saw the Londoners fall behind after just four minutes.
Hutchison's quick free-kick on the halfway line was intercepted by Simon Brown and he raced clear to the edge of the area, only to be robbed by Paul Robinson as he shaped to shoot.
Mansfield went even closer in the 22nd minute, Barker's stooping far-post header on the end of an inswinging Jake Buxton cross, bouncing across the face of goal and narrowly wide.
The underdogs were made to pay for that miss just two minutes later. The Stags failed to clear a corner and Carl Asaba hooked the ball goalwards for Ben May to head in from close range.
Brown again went close for the home side, glancing Gus Uhlenbeek's cross narrowly past the angle of post and crossbar.
Then Barker just failed to touch in a Brown cross and Rundle's goalbound drive was blocked by Robinson as the Stags pressed hard for an equaliser.
After Mansfield squandered more chances at the start of the second half Robinson finally looked to have ended Mansfield's resistance in the 62nd minute. The defender was left totally unmarked to head in Hutchison's corner via the palms of keeper Kevin Pressman.
Five minutes later Brown gave Mansfield hope with a deserved goal. Uhlenbeek's long-range drive was tipped on to the post by Andy Marshall and Brown slid in to score.
Within 90 seconds the Stags were level, Brown feeding Barker, who placed a deft finish around Marshall to leave Millwall shellshocked.
In the 79th minute Barker almost stabbed in a winner for the home side after incessant home pressure, but then came Livermore's heartbreaker.