The win gives the Blaugrana 64 points from 29 matches, five points ahead of Real Madrid who have yet to play this round.
Teenager Ansu Fati opened the scoring three minutes from halftime with a composed finish after receiving the ball at the edge of the box.
Messi added the second from the penalty spot in the 69th minute after drawing a Jonathan Silva foul in the box -- the Argentine sending goalkeeper Ivan Cuellar the wrong way to move within a goal of 700 for club and country.
It was Messi's 56th converted penalty in La Liga and saw him draw level with Hugo Sanchez as the league's second-top penalty taker, behind record holder Cristiano Ronaldo on 61.
"It's important to keep winning although we need to play with more speed than we did today but we've got six points and we're going to get better in each game," said Barca midfielder Ivan Rakitic.
"All teams have a lot at stake at this stage so we expected a tough game, they made it difficult for us to find space and they committed a few fouls but things got easier as the game went on."
Barca manager Quique Setien praised Fati for his work and for scoring the goal.
"He did a good job, both in attack and defence. It's true he still lacks some things, but he needs the consistency that he still doesn't have due to the injury problems that prevented him training some days," Setien said. "He did really well when he was on but didn't want to put him at risk anymore after those problems."
Setien also singled out Antoine Griezmann for his role in the match amid struggles since his move from Atletico Madrid last summer.
"I'm very happy with his hard work. He moves, looks for the space, tries to pull rivals out of position to create space for teammates. On the defensive side when we lose the ball he is so important.
"He got a goal today but it was ruled out. He's really important for us."
Barca had enjoyed a dream return to action by thumping Real Mallorca 4-0 while Leganes were beaten at home by Real Valladolid in their first game back but the minnows produced a brave display and should have made more of their bright start.
Barca defender Clement Lenglet had to scramble clear a shot from Leganes forward Miguel Angel Guerrero early in the game and moments later Guerrero struck the post from a tight angle.
Barca's Camp Nou is far from the most atmospheric of stadiums in Spain but this time there were no fans at all to give the team a boost as spectators are currently barred from all La Liga matches for safety reasons due to the COVID-19 pandemic.
The 99,000-capacity arena last stood empty for a league game when Las Palmas visited in a 2017 fixture which was played without fans as a protest against a police crackdown during Catalonia's banned referendum on independence.
"I went out for a walk around before the game. It's totally different. It's a little like losing an important part of what football is. you lose the essence the sound: the applause, the cheering, the rustle of the fans. You notice it," Setien said.
Barcelona are next in action on Friday when they visit third-placed Sevilla. Leganes, who sit bottom of the table with 23 points, will visit Mallorca the same day.
Information from ESPN's Sam Marsden and Reuters was used in this report.