A 2-0 loss at Valencia on Saturday resulted in reigning LaLiga champions Barca falling three points adrift of rivals Real Madrid in the title race, but they appeared to get right back on track at Camp Nou on Thursday.
Setien named a strong starting line-up and Antoine Griezmann took less than four minutes to open the scoring, with Clement Lenglet nodding in the second before the half-hour mark.
Messi extended their advantage with a fortuitous finish in the 59th minute, and he doubled his tally after substitute Arthur found the back of the net to send Barca breezing into the quarter-finals.
After Nelson Semedo played a give-and-go with Messi, he cut the ball back to Griezmann, who fired between Chidozie Awaziem's legs and into the bottom-left corner to give Barca an early lead.
Setien's team dominated possession and had a second goal for Griezmann ruled out in the ninth minute, with Jordi Alba deemed to have been marginally offside in the build-up.
And Griezmann has another goal waved off! The play was offside by millimeters! pic.twitter.com/zvAieh2SKW
— FC Barcelona (@FCBarcelona) January 30, 2020
Griezmann saw a deflected shot tipped around the post by Ivan Cuellar, but Lenglet nodded the resulting corner from Messi over the Leganes goalkeeper and into the far corner to increase Barca's advantage in the 27th minute.
The visitors sporadically threatened on the counter-attack, yet their hopes of getting back into the game were extinguished when Messi raced away on the right and beat Cuellar with the help of a deflection off Rodrigo Tarin.
Leganes coach Javier Aguirre was shown a yellow card for dissent, and his mood would not have improved in the 77th minute, Arthur firing home after Cuellar denied Ansu Fati and Awaziem blocked Messi on the initial follow-up.
Messi rounded off a magnificent display with one minute remaining by latching onto Ivan Rakitic's throughball, rounding Cuellar and sending the ball into the roof of the net.
What does it mean? Barca could rue not getting another striker
With a move for Valencia attacker Rodrigo Moreno having broken down, Barca director Guillermo Amor said they were happy to finish the transfer window without signing attacking cover for Luis Suarez, who has been ruled until close to the end of the season with a knee injury.
This match would have been a good opportunity for Barca to grant Griezmann and Messi a rest, even though they proved pivotal to the result. They are now even more crucial in the run-in and no risks can be taken with the star pairing.
It was not a spectacular display from Barcelona, but Messi was involved in all five goals. He released Semedo for the opener, assisted Lenglet for the second and got the third and fifth himself. Arthur would not have got on the scoreboard were it not for the Argentina star's initial rebound either.
Not so sterling Silva
It was never going to be an easy task for Jonathan Silva, but he struggled to provide any resistance on the left and lost possession 12 times before being replaced by Kevin Rodrigues in the 57th minute.
Barcelona host Levante in LaLiga on Sunday, when Leganes entertain Real Sociedad.
Photo Getty Images Caption: Barcelona players celebrate during their win over Leganes