Turkish President Recep Tayyip Erdogan has narrowly won a referendum to expand presidential powers, which could keep him in office until 2029.