The Middlesbrough defence failed to clear Kieran Trippier's corner and, when the ball fell to Harewood in the six-yard box, the former West Ham and Aston Villa striker steered into the bottom corner.
Forest twice almost levelled when Morgan nodded over and then Luke Steele saved well from Earnshaw, but it was Barnsley who scored again when Trippier got away down the right and outfoxed Cohen before crossing for Gray to head home.