The Navy and Marine Corps will prohibit foreign troops from buying and carrying personal weapons as the military continues rolling out new restrictions after a Saudi officer carried out a terrorist attack on a U.S. military base.

International service members training with sailors and Marines at bases in the U.S. or its territories face a host of new rules on personally owned firearms and ammunition, the services announced last week. The restrictions also apply to foreign troops' family members accompanying them.

Foreign troops assigned to Navy and Marine Corps bases, regardless of their country of origin, will be prohibited from possessing, storing, using, transporting, carrying, purchasing, selling or transferring personally owned firearms, weapon components or ammunition, the new policies state.

All international military students will have to sign agreements on the new rules or risk getting booted out of the U.S. Those training with the Navy must do so by April 15 and those training with Marines by May 1.

Related: Marine Corps Limits Foreign Troops' Base Access After Pensacola Attack

International troops' family members over the age of 18 must also sign the agreements.

"Failure to do so will result in immediate expulsion from training or school, and orders generated for immediate transfer back to their home country, to include accompanying family members," the Marine Corps' message states.

Foreign service members and their families will have no access to personally owned weapons or ammunition "until after returning to their home country," according to the Navy's policy.

The new restrictions are part of a Pentagon-wide review of security measures following a Dec. 6 shooting on a Navy base in Pensacola, Florida. A Saudi officer training there lawfully purchased a semiautomatic handgun with an extended magazine through a hunting-license loophole.

The exception allows non-immigrant visa holders who otherwise are not permitted to buy firearms or ammunition to purchase them if they have a valid state-issued hunting license permit or other required documentation, David Bowdich, deputy director of the FBI, said last month.

The Saudi lieutenant used the weapon he bought to open fire on a classroom, killing three sailors and injuring several more.

International students who were previously given permission to carry their own weapons and ammunition will have to transfer them to a base armory or other authorized officials for the duration of their assignment, ship them to someone outside the U.S., or dispose of them in accordance with local policies and laws.

The new rules won't apply to government-issued firearms and ammunition foreign troops use while under the supervision of the Navy or Marine Corps as they train, the messages add.

Acting Navy Secretary Thomas Modly on Jan. 31 instructed the Navy and Marine Corps to update their policies prohibiting foreign troops from carrying their own weapons.

This is the third update the Marine Corps has made to base security in the wake of the Pensacola shooting. Earlier this month, the Marine Corps announced that foreign troops will be allowed to access only the base to which they are assigned. Previous policy allowed international military students to move between bases more freely.

The Marine Corps also recently announced it would allow about 3,000 law enforcement personnel to carry concealed weapons on base, even when off duty.

-- Gina Harkins can be reached at gina.harkins@military.com. Follow her on Twitter @ginaaharkins.

Read more: Some Marines Get OK to Carry Concealed Firearms After Deadly Shootings