A sensational strike from David Alaba and a late goal from Lucas Vazquez gave Real victory at the Camp Nou.
Sergio Aguero scored a consolation with almost the last kick.
Defeat leaves Barcelona down in eighth place in La Liga, five points behind leaders Real Madrid, Sevilla and Real Sociedad.
Barcelona controlled possession in the first half but Real were lethal on the counter-attack, taking the lead when Alaba started a flowing move with a tackle and finished it at the other end with a left-footed drive from the edge of the box.
Koeman brought on Philippe Coutinho at half-time, while strikers Sergio Aguero and Luuk de Jong were also thrown on in the second half as they searched for an equaliser.
With seven minutes of injury time added on, Real doubled their lead when Marc-Andre ter Stegen saved a shot from Marco Asensio from another counter-attack but Vazquez pounced on the rebound to score.
Barca got a goal back in the 97th minute when Sergino Dest crossed to the Aguero in the six-yard box and the Argentine tapped in but it proved to be a consolation goal.
Additional reporting: Reuters