Brazil have won the Confederations Cup after thrashing world and European champions Spain 3-0 in a one-sided final at a raucous Maracana Stadium.