A Democratic bill, which would have reopened the government with no strings attached, received more votes than the bill backed by Mr. Trump, which included temporary protections for some undocumented immigrants in exchange for $5.7 billion for his proposed border wall.