North End, who have won just twice on home soil this season, led through an early header from defender Craig Morgan.
But Tykes winger Adam Hammill's spectacular strike deservedly hauled the visitors level shortly before half-time and on-loan Birmingham striker O'Connor capitalised on a defensive error to settle the match in the 89th minute.
Preston went close inside the second minute when striker Jon Parkin collected possession 18 yards from goal and hit a fierce shot.
Jason Shackell blocked his effort but Preston led in the fourth minute when winger Keith Treacy crossed in a free-kick from the right flank and Morgan headed home from six yards out.
Five minutes later, North End went in search of a second goal when Parkin fired a sweet shot goalwards from 18 yards.
Tykes goalkeeper Luke Steele made a fine parried save to avert the danger but the visitors gradually gained a foothold on proceedings.
In the 16th minute, an outswinging corner from Hammill was met by Stephen Foster, who powered a firm header goalwards which drew a fine save from Preston goalkeeper Andy Lonergan.
Two minutes later, Hammill drilled a 30-yard shot over the bar and moments later the Tykes went close again from another corner.
Hammill's left-wing delivery was greeted by Goran Lovre's header from 12 yards and Lonergan was again on hand to deny the visitors with a fine save.
In the 26th minute, Preston were found wanting again from a set-piece which saw Shackell head goalwards from 12 yards before a fine save from the in-form Lonergan deflected the ball to safety.
Treacy then shot wide for Preston and Darel Russell had a shot tipped around a post by Steele, but the momentum was largely with Barnsley and they drew level a minute before the break.
Hammill collected possession 30 yards from goal and unleashed an unstoppable shot which flew into the top right-hand corner past a helpless Lonergan.
North End were then dealt another blow when Billy Jones succumbed to injury and was replaced by David Gray at the break.
In the 55th minute, Barnsley frontman Andy Gray had a chance to shoot from 18 yards but his effort was tame and Lonergan made a comfortable save.
The visitors went close in the 63rd minute when Hammill's free-kick was met by Shackell but his header from six yards flew over the crossbar.
Moments later Hammill tried his luck from distance but Lonergan was equal to it and then Russell headed over the crossbar for Preston.
Just as the points looked set to be shared, O'Connor collected possession after a mistake from Sean St Ledger to fire home from 12 yards to leave Deepdale stunned.