Democrats have made historic gains in the US midterms, dealing a major setback to President Donald Trump.