Four Republican senators joined Democrats in voting against the legislation, which was backed by President Donald Trump.