The action is a victory for President Donald Trump in the biggest legal controversy of his young presidency.
Mr Trump said last week that the ban would take effect within 72 hours after being cleared by courts.
The justices will hear arguments in the case in the autumn.
The ban would apply to citizens of Iran, Libya, Somalia, Sudan, Syria and Yemen.
The court did leave one category of foreigners protected, those “with a credible claim of a bona fide relationship with a person or entity in the United States”, it said in an unsigned opinion.
The Trump administration said the ban was needed to allow an internal review of the screening procedures for visa applicants from those countries.
That review should be complete before October 2, the first day the justices could hear arguments in their new term.