Gatland's glorious 12-year stint as Wales coach came to an end after the Rugby World Cup, where he led the team to the second fourth-place finish of his tenure, but the New Zealander was back in Cardiff to lead his old team's opponent.
His successor Pivac made a winning start as wing Josh Adams and hooker Ken Owens crossed for two tries apiece, although a late BaaBaas fightback meant the margin of victory was only 10 points.
Gatland was afforded a rousing reception when he was shown on the big screen at Principality Stadium while BaaBaas captain Rory Best, Ireland's most-capped forward, was given a standing ovation when he was substituted in the second half of his final appearance.
Wales led 19-7 at the break as Adams, the Rugby World Cup's leading try scorer, went over along with international debutant Johnny McNicholl and Owens.
Further tries from Owens and Adams after the break put Wales firmly in charge, while substitute Gareth Davies also got in on the act.
The Barbarians scored five tries in total — four of them coming after the break — as Josh Strauss, Curwin Bosch, Shaun Stevenson, Craig Millar and Peter Samu all crossed.