Espanyol held the European champions 0-0 in a bad-tempered first of three meetings between the sides in 10 days at the weekend and threatened an upset early on through Felipe Caicedo's composed finish.
Yet, Messi took just four minutes to restore parity before blasting a stunning free-kick in off the underside of the bar just before half-time.
The Argentine teed up Gerard Pique for a third and then Neymar for a sensational volleyed finish two minutes from time to hand Barca a commanding advantage ahead of the second leg on January 13.
Arda Turan was handed his Barca debut after joining from Atletico Madrid in July as the Catalans' year-long ban on registering new players came to an end on Monday.
Also Read
Yet, Barca were stunned on nine minutes when on-loan Real Madrid midfielder Marco Asensio robbed Dani Alves and played in Caicedo to slot home.
A wonderful through ball from Andres Iniesta ensured the lead was short-lived as Messi fired past Lopez.
Brilliant passes from Iniesta and Messi then teed up Pique for an easy finish to all but kill the tie off.
Espanyol lost their cool in the final quarter as Lopez somehow escaped with a blatant stamp on Messi inside the area before Perez and Diop were sent-off in a four-minute spell.
And Neymar finally made the visitors pay when he volleyed home first time from Messi's scooped pass.
Elsewhere, Alvaro Negredo scored a hat-trick as Gary Neville enjoyed just his second win in seven games in charge of Valencia with a 4-0 thrashing of Granada.
"We are better physically, in our play and our confidence, but obviously we have a long way to go and we can't get carried away with just one win."
The visitors counter-attacked to perfection before the
break to take a commanding lead through Leo Baptistao and Samu Garcia despite resting a host of first-team regulars to prioritise their push for a top-four finish in La Liga.
However, Inaki Williams's early strike after half-time brought last year's finalists back into the game before Aritz Aduriz came off the bench to score his 22nd goal of the season and Aymeric Laporte rounded off the comeback 10 minutes from time.
Mirandes, one of only two sides from outside the top flight left in the competition, maintained their hopes of reaching the last eight as Alberto Lopo's late equaliser rescued a 1-1 draw for Deportivo la Coruna.
La Liga leaders Atletico Madrid also face a derby later against Rayo Vallecano.