Barca should have killed the game off in the first half as Luis Suarez and Messi missed two big chances each against La Liga's bottom side.
However, Suarez rounded off a fine team move to break the deadlock just before the hour before Messi's double in the final 17 minutes moved him ahead of Cristiano Ronaldo as La Liga's top scorer with 11 for the season.
Real can extend their lead once more and set a new club record unbeaten run of 35 games when they host Deportivo la Coruna later on Saturday.
"We are Barcelona and we know we can never give up," Suarez told BeIN Sports Spain.
"We are candidates to win the league, it doesn't matter if we are four, five, six or seven points behind, we won't give up."
Barca were in desperate need of a lift after conceding in the last minute to Real in last weekend's El Clasico.
The Catalans' upturn in performance since captain Andres Iniesta's return from a six-week injury layoff continued in the first half at Osasuna, but Barca were in danger of paying for their profligacy in front of goal.
Suarez fired wide when through on goal and then hit the post inside 20 minutes.
Osasuna remain five points off safety and it was easy to see why they are still without a home win all season as the hosts were opened up at will.
Suarez turned provider for Messi, but Nauzet Perez rushed from his goal to block.
And the goalkeeper frustrated the five-time World Player of the Year again moments later by just raising a hand in time to divert Messi's attempted chip behind.
"We were patient and generated a lot of chances," said Barca boss Luis Enrique.
"It was key to go in front and calm ourselves down.
"The goals came in the second-half, but we deserved to go in front in the first-half and have a much easier game."
Sergio Leon gave Barca a scare at the start of the second-half when his brilliant lob over Marc-Andre ter Stegen came back off the underside of the bar.
Barca created fewer chances in the second half, but were more clinical.
Sergio Busquets and Messi combined to release Jordi Alba on the left and his low cross was rolled into an unguarded net by Suarez despite Osasuna calls for offside.
The second goal came about in similar fashion 13 minutes later as Alba again got to the by-line and his cross was volleyed home by Messi at the near post.
And Messi didn't need any help for his second in stoppage time as he wriggled clear of three Osasuna defenders and left Perez on the floor before lifting the ball high into the net.
Valencia remain above the relegation zone only on goal difference despite more penalty heroics from goalkeeper Diego Alves in a 3-2 defeat at Real Sociedad.
Alves saved the 23rd penalty of 47 he has faced in Spanish football from Carlos Vela, but it mattered little as a Willian Jose double and Juanmi's injury time strike moved Sociedad up to fourth.
Valencia have won just one game in eight since former Italy boss Cesare Prandelli took charge in October.