The home side led through Elvis Hammond's strike in the final seconds of the opening period after Southend had controlled most of the half. Dave Bird's cross fell to Andy Gallinagh, whose attempted shot was forced over the line by Hammond from close range.
Loan defender Matt Heath was left all alone in the penalty area to meet Alan McCormack's cross in the 20th minute, but he guided his header against the left post.
Southend levelled when Heath headed Simon Francis' cross back into the six-yard box and Barnard stooped to head over the line in the 76th minute.
The winner came with two minutes to go when Francis crossed for Barnard to nod home at the far post and send the 176 travelling fans wild.