Gavi put Barca ahead with a 33rd-minute strike teed up by Lewandowski, and the roles were then reversed when the latter's finish extended the lead just before the break.
Gavi registered another assist when Pedri added the third in the 69th minute, with Karim Benzema grabbing a consolation for Real in stoppage time as Barcelona - currently three points clear of Carlo Ancelotti's defending champions at the top of LaLiga - secured their first trophy under Xavi.
Atletico Madrid are fourth in the table after being held 1-1 at Almeria, where Angel Correa's 18th-minute opener for the visitors was cancelled out by El Bilal Toure towards the end of the first half. Atletico finished the game with 10 men due to a late red card for Sergio Reguilon.
Espanyol moved out of the relegation zone with a 2-1 win at Getafe. Joselu put the away side in front in the sixth minute, Enes Unal equalised a minute later, and Javi Puado then scored the winner just past the hour mark.
In Ligue 1, leaders Paris St Germain slumped to a second defeat in three league games as they were beaten 1-0 at Rennes.
Hamari Traore notched the only goal in the 65th minute as Christophe Galtier's men were left with a three-point lead over second-placed Lens, who beat them on New Year's Day.
Rennes are fifth with the same amount of points as fourth-placed Monaco, who thrashed struggling Ajaccio 7-1 at Stade Louis II with Wissam Ben Yedder scoring a first-half hat-trick.
Ben Yedder's 35th-minute penalty capped a treble that added to efforts from Axel Disasi and Krepin Diatta as the hosts went 5-1 up in the first half, before Breel Embolo further boosted their tally with a second-half brace.
Lille, in sixth, also produced a thumping home win as they beat Troyes 5-1, Mohamed Bayo and Jonathan David each netting twice and Alan Virginius also getting on the scoresheet for Les Dogues.
Clermont won 2-1 at rock-bottom Angers thanks to goals from Elbasan Rashani and Neto Borges, and Nantes won 3-0 at nine-man Montpellier, where the match had to be stopped for around 15 minutes during the first half due to smoke bombs being thrown from the stands.
Montpellier had Wahbi Khazri and Elye Wahi sent off either side of the interval. Andrei Girotto scored scored deep into first-half stoppage time and there were subsequently late goals for Mostafa Mohamed and Ludovic Blas.
Toulouse drew 1-1 at home with Brest, and it ended goalless between Reims and managerless Nice.
In Serie A, Lazio won 2-0 at Sassuolo via a Mattia Zaccagni penalty and late Felipe Anderson goal, while Atalanta demolished Salernitana 8-2.
Ademola Lookman netted twice for the hosts, once from the spot, and Jeremie Boga, Giorgio Scalvini, Teun Koopmeiners, Rasmus Hojlund, Ederson and Nadir Zortea were their other scorers.
Paulo Dybala got a brace as Roma won 2-0 at the Stadio Olimpico against Fiorentina, who had Dodo sent off midway through the first half.
Lazio, Atalanta and Roma are all three points outside the Champions League places in fifth, sixth and seventh respectively.
Stefan Posch scored a late winner as Bologna came from behind to win 2-1 at Udinese, and M'Bala Nzola's penalty secured Spezia a 1-0 win at Torino.