Philippe Coutinho opened the scoring after Dembele's shot was parried and Paulinho tapped home a second.
Lionel Messi poked home following Andres Iniesta's exquisite first-time pass over the defence.
Nicola Sansone pulled one back for Villarreal before Demeble's late double.
He scored into an empty net after good work by Ivan Rakitic and then scored a magnificent second, as he picked the ball up on the halfway line, took on several defenders and chipped Sergio Asenjo from the edge of the box.
Iniesta came off to a standing ovation just before the hour mark. The Barca captain is leaving the club he has spent his entire career at this summer, although there are reports his expected move to China is in doubt.
Ernesto Valverde's Barca now just need to avoid defeat at Levante and at home to Real Sociedad in the next two weekends to become the first team in the modern era to go a whole La Liga season unbeaten.
The last team to achieve the feat was Real Madrid in 1931-32 when there were 18 games in a season.
Read More (...)