It also noted that there are 22 percent more residencies available each year than there are American graduates to take them. Graduates of foreign medical schools now fill that gap; the largest number come from India, followed by Pakistan, China, the Philippines, Iran and Israel.

(Iran is on Mr. Trump’s exclusion list; Pakistan, a Muslim-majority country with a history of internal and external terror attacks, is not.)

Many foreign graduates have J-1 visas, which give them about three years to complete their residencies. “They must pass licensing exams and they must do a residency to practice here, even if they’re superstars where they come from,” said Phillip Miller, a Merritt Hawkins spokesman.

Foreign-born graduates have often worked at world-class institutions and have published academic papers, so they have higher average scores than American graduates on the medical knowledge portions of the licensing examinations, according to Merritt Hawkins research — though most initially score lower on the clinical skills portions, which include English and communication skills.

“I had to work my butt off to get here,” said Dr. Abdelghani el Rafei, a first-year resident at the University of Minnesota. “They only take the top graduates from schools in countries like mine.”

Such foreign-born graduates must return home when their visas expire, but they can get extensions if they agree to work in an area that the Department of Health and Human Services considers “medically underserved,” which is roughly defined as having less than one primary care doctor for every 3,000 people.

Those who practice in an underserved area for several years can apply for green cards. “After that, they can practice anywhere, but at least you’ve had three or four years of a physician in your town, and that’s pretty significant,” Mr. Miller said.