Scottish midfielder O'Brien seized on Martin Cranie's long ball over the top in the fourth minute to round Millwall goalkeeper David Forde and slot home his third goal of the season.
Millwall, who, like Barnsley, had won just one of their previous 12 league games, went close in the second half through Shaun Willians and DJ Campbell but they failed to find an equaliser, leaving them two points above their opponents and a place outside the drop zone.
The hosts scored what proved to be the winner with the game's first chance.
Captain Cranie played a diagonal pass over the head of Lions left-back Scott Malone and O'Brien showed composure to chest the ball down, beat Forde and find the net from just inside the area.
Barnsley were buoyed by the goal and top-scorer Chris O'Grady fired over after good work by Dale Jennings in the 10th minute before the Tykes winger shot tamely at keeper Forde when clear on the left.
The visitors gradually came back into the game and, after a mistake by Tykes defender Peter Ramage, on-loan striker Campbell shot marginally wide from the edge of the 18-yard area in the 23rd minute with home keeper Luke Steele out of his goal.
Steele then produced a brilliant diving save to deny a goal-bound Steve Morison header, following a Scott McDonald cross from the right.
The Tykes went close to doubling their advantage two minutes before the break but Ramage's header from a corner was repelled on the line by Millwall defender Shane Lowry.
The start of the second half saw a high tempo game with little quality and it took until the 71st minute for a notable chance to be created.
Lions midfielder Williams found time and space on the edge of the box to line up a powerful drive, which was touched past the right-hand post by Steele.
Millwall, whose only away success of the season came at Charlton in September, were again thwarted by Steele moments later as the Barnsley keeper blocked Campbell's close-range effort.
A defensive mix-up at the other end almost allowed Barnsley to grab a second in the 77th minute but O'Grady's effort from range was blocked by the defence after keeper Forde failed to clear the ball when out of his goal.
Danny Wilson's side then went even closer with nine minutes remaining.
Substitute Brek Shea teed up Jennings inside the area and the wide-man's placed effort was parried by Forde, before the keeper smothered O'Grady's follow-up attempt.
Millwall had one final chance to find an equaliser two minutes from the end but Williams' 25-yard free-kick flashed the wrong side of the right-hand upright.