Barca were frustrated by opponents who defended well but the introduction of fit-again forward Neymar for the final half hour gave them an extra attacking edge.
It was Lionel Messi, though, who opened up the Villarreal rearguard with a cross along the goalline that was turned in by Ramirez to lift Barca to six points from their opening two games.
"I am happy on a personal level but above all for the work of the team," Ramirez told reporters. "Thanks to Leo I could score the winning goal. Messi and Neymar are fantastic players although this is the work of all of us and we are all happy."
Luis Enrique played the promising Munir El Haddadi, who scored last weekend, ahead of Neymar in Barcelona's starting line-up.
Barca had the majority of the ball but struggled to find space going forward against a well-organised Villarreal side and it was only following Neymar's entry that the chances began to build up.
Messi hit the post with a free-kick from the right of the area in the first half but Barca were also lucky when Jeremy Mathieu turned a cross onto an upright.
Tomas Pina and Messi again hit the woodwork for either side midway through the second half before Neymar found Messi, who looked up and picked out Sandro to score and give the Catalan side the three points.
- Sports & Recreation
- Lionel Messi