Barcelona edged Real Madrid 3-2 in Jeddah to win a record 16th Spanish Super Cup, with Raphinha scoring twice and Lewandowski on target.