Barnsley held off a late Middlesbrough fightback to earn a 3-2 win at Oakwell and move off the bottom of the Sky Bet Championship.