A man carries toilet paper after crossing the border from Tijuana, Mexico, to San Diego, Wednesday, March 18, 2020, in San Diego. (AP Photo/Gregory Bull)

Mexico and the U.S. announced Friday that they would prohibit all "non-essential" travel across their shared border as part of efforts to control the spread of the coronavirus.

Both countries and Canada also agreed to immediately turn back anyone trying to illegally cross a border, with U.S. officials saying that the unchecked entry of people from around the world poses a potential risk because of the rapidly spreading virus.

"The actions we are taking together with our North American partners will save countless lives," President Donald Trump said in announcing the measures.

Trump administration officials and Mexican Foreign Secretary Marcelo Ebrard said the travel restrictions would be similar to those put in place earlier this week along the U.S. and Canadian border: People could still cross for medical reasons or for school but not for tourism or recreation.

"Everyone else is not expected to have any difficulties," he said. "We're not talking about closing it."

The ban, which takes effect at midnight Friday, does not include commercial traffic and remains in place as long as needed, Secretary of State Mike Pompeo said.

By excluding commercial traffic from the ban, the two governments substantially softened the economic effects. Also, fewer Americans are heading south because of a statewide stay-at-home order in California and a State Department warning advising Americans not to travel abroad.

Secretary of State Mike Pompeo, right, listens as President Donald Trump speaks during a coronavirus task force briefing at the White House, Friday, March 20, 2020, in Washington. (AP Photo/Evan Vucci)

Still, the restrictions are a major development along the world's most heavily crossed border. Mexican shoppers are the lifeblood for smaller U.S. border towns and it is common for people in both countries to cross frequently to visit family and friends.

As news of the ban spread, people like 68-year-old El Paso resident Silvia Shadden rushed to cross even if her reason could meet the definition of essential. Walking with a crutch, she returned from getting a weekly vitamin injection from a doctor in Mexico's Ciudad Juarez that costs a fraction of what it does in the U.S.

"I went to Juarez to see the doctor and get my injection," Shadden, who suffers from a vitamin deficiency that causes muscle atrophy, said as she walked from the U.S. border checkpoint.

Trump said the border restrictions and the plan to immediately return anyone detained while illegally crossing are intended to curb the spread of the virus in detention facilities as well as a "mass global migration that would badly deplete the health care resources needed for our people."

Acting U.S. Homeland Security Secretary Chad Wolf told reporters at the White House that the restrictions were aimed at eliminating non-essential travel across that border.

A border patrol agent walks along a border wall separating Tijuana, Mexico, from San Diego, Wednesday, March 18, 2020, in San Diego. (AP Photo/Gregory Bull)

"We want to make sure that cargo continues, trade continues, heath care workers continue to be able to traverse that border," Wolf said. "But tourism, some recreational activities and other things needs to stop during this crisis."

The U.S. is citing a law that allows restricting immigration to prevent the spread of communicable disease for its plan to immediately turn back to Mexico anyone who crosses the border without legal authorization.

The measure would cover migrants crossing illegally into the United States as well as into Canada, where some people have fled to escape U.S. enforcement efforts. Ebrard, reacting to reports that the U.S. planned to send people from elsewhere into his country, said Mexico would only accept the return of migrants from Central America and Mexico,

Trump said he supported the Mexican position. "Why would Mexico take people who aren't from Mexico?" he said. "They go back to the country from where they came."

U.S. Customs and Border Protection officials say a long list of "essential" workers would be unaffected going to and from their jobs, including farm workers, restaurant and grocery store employees and bus drivers. Mexico was preparing similar restrictions on visitors from the United States.

President Donald Trump, left, listens as Secretary of State Mike Pompeo speaks during a coronavirus task force briefing at the White House, Friday, March 20, 2020, in Washington. (AP Photo/Evan Vucci)

Keeping trade flowing, as the U.S. and Canada also agreed to do, contains the economic damage. Mexico is the U.S.'s largest trading partner, just ahead of Canada. The U.S. accounts for about 75% of Mexican exports, including autos, computers and medical devices.

Even with the exceptions, it's a major blow to border economies. An average of 40,000 cars enter the U.S. daily from Tijuana, Mexico, at the nation's busiest crossing in San Diego, which has a second crossing that funnels about 19,000 cars a day. About 30,000 cars enter El Paso daily from Ciudad Juarez, Mexico.

The State Department on Thursday issued a new travel alert urging Americans not to go abroad under any circumstances and to return home if they are already abroad unless they plan to remain overseas. California Gov. Gavin Newsom ordered the state's 40 million residents to stay at home, restricting nonessential movements.

"People are not crossing anyway," said Avila, who is also the San Diego Regional Chamber of Commerce vice president for international business affairs. "This is the right thing to do. If you don't have to cross, don't."