Four Republicans allied with Democrats to pass bill to rein in Trump, though it is likely to face a presidential veto.