After reaching the Champions League semi-finals this season, knocking out former champions Juventus and Bayern Munich on the way, Unai Emery"s side entered the final week of the season in danger of missing out on European competition completely.
With the top six already determined, Villarreal started the day in seventh, one point ahead of Athletic Bilbao who were playing at fourth-placed Sevilla at the same time on Sunday.
They needed to win at Camp Nou to guarantee qualification against a second-placed Barca side who had nothing left to play for and put up little fight.
Pedraza scored the opener in the 40th minute with a precise shot after receiving a fine through ball from Dani Parejo and Moi Gomez sealed the win in the 54th, striking powerfully home from close range after Adama Traore made a mistake while trying to clear the ball from his own area.
Athletic ended up losing 1-0 to Sevilla to finish in eighth place, four points behind Villarreal.
Betis and Real Sociedad finished fifth and sixth to qualify for the Europa League.
Champions Real Madrid, Barcelona, Atletico and Sevilla qualified for the Champions League.
Alaves, Levante and Granada were relegated to the second division.