A left-wing legislator Gabriel Boric who rose to prominence during anti-government protests in Chile has been elected the country's next president.