The United States beat Ecuador 2-1 to reach the semi-finals of the Copa America in a match in which both teams had a man sent off.