New South Wales Labor has ended its 12 years in the political wilderness, returning to power and giving the party control of every mainland state and territory.