Former Bayern Munich boss Flick has now won all three Clasicos since taking charge of Barca in the summer.
One was the Spanish Super Cup final, but this counts as his first major trophy with the Catalans.
Conversely, it could have been Carlo Ancelotti's last chance to add one final crown at Real. The Italian legend is widely expected to be replaced at the end of the season - and they sit four points behind La Liga leaders Barca, although there is one more Clasico to come in the league.
This was a topsy-turvy game.
Barcelona should have scored more in the first half with Yamal going close, Kounde having a header saved by Courtois and Dani Olmo hitting the post.
But Real were much better when Mbappe, who was a doubt with a knee injury, came on at the break.
He won a free-kick which he bent into the bottom corner - his 33rd goal for the club. And after Tchouameni's goal, it appeared as if they were going to win.
But Torres popped up to beat Courtois, who had rushed outside his box before a tidy finish.
There were plenty more chances too, with Vinicius and Raphinha - Brazil team-mates but Clasico rivals - both missing opportunities.
In extra time Torres went close for Barca before Kounde smashed in a memorable winner.
The fourth and final Clasico of the season, in La Liga on Sunday, 11 May, could go a long way to deciding if Barcelona will win the double.
In fact Barcelona - who were missing top scorer Robert Lewandowski for this game - could win the treble, as they face Inter Milan in the Champions League semi-finals.