Ibrahimovic replaced Thierry Henry early in the second half and fired Barca in front less than five minutes later as he volleyed home Dani Alves' cross.
Barcelona were reduced to 10 men with almost half an hour left, when Sergio Busquets was sent off for a second bookable offence.
But Madrid, who had earlier missed a fantastic chance to take the lead when the unmarked Cristiano Ronaldo - in his first ever 'Clasico' - shot straight at Victor Valdes with only the Barca keeper to beat, failed to take advantage and themselves had Lassana Diarra dismissed late on.
Ronaldo went off with 25 minutes left and Barca should have made things easier with two minutes to go, when Lionel Messi found himself alone with only Iker Casillas to beat, but the Argentina winger shot straight at the Madrid keeper, who deflected the ball over with his feet.
The result sees Barca leapfrog Real back to the top of the Liga table and two points clear.