President Trump signed a $716 billion defense bill Monday that authorizes hundreds of new planes, ships and tanks — and delivers a substantial victory to the administration by watering down penalties on a Chinese telecom company.

The law adds thousands of troops to the size of the military, raises pay, modernizes the U.S. nuclear arsenal and lays the groundwork for Mr. Trump’s proposed “space force,” in what the president called “the most significant investment in our military, and in our war fighters, in modern history.”

“After years of devastating cuts, we’re now rebuilding our military like never before,” Mr. Trump said while signing the National Defense Authorization Act at Fort Drum, New York. “Every day our military was fighting for us, and now we’re fighting for you.”

The bill draws up policies to carry out the massive cash infusion lawmakers agreed to earlier this year for the military, ending years of budget “sequestration” caps under President Obama.

Mr. Trump’s signature also marks the earliest that an NDAA has been competed in more than 20 years.

The White House said the law will increase the size of U.S. forces by authorizing 15,600 more troops across the Army, Navy, Air Force, and Marine Corps. The new recruits will bring the total strength of the Army to 487,500 soldiers; Navy, 335,400 sailors; 186,100 in the Marine Corps; and 329,100 in the Air Force.

Mr. Trump also got what he wanted in the measure with controls on U.S. government contracts with China’s ZTE Corp. and Huawei Technologies because of national-security concerns. The legislation prohibits government agencies from using their products, but stops short of a complete ban on any dealings between ZTE and American companies.

Such a ban had passed as part of the Senate’s version of the NDAA, after ZTE had been deemed a repeat-violator of American sanctions. But Mr. Trump struck a deal to lift the sanctions at the personal request of Chinese President Xi Jinping, who has been helping Mr. Trump in his efforts to negotiate with North Korea on denuclearization.

Instead, the NDAA strengthens the Committee on Foreign Investment in the United States, which determines whether proposed foreign investments threaten national security.

Huawei said it supports the U.S. government’s goals for better security, “but this random addition to the NDAA is ineffective, misguided, and unconstitutional.”

“It does nothing to identify real security risks or improve supply chain security, and will only serve to stifle innovation while increasing internet costs for US consumers and businesses,” the company said.

The president also said the measure will help to create the new U.S. Space Force, which he said is necessary to counter military moves by China and others in orbit.

“Our foreign competitors and adversaries have already begun weaponizing space, developing new technologies to disrupt vital communications, blind satellites,” Mr. Trump said. “They’ve given me rundowns. I’ve seen things that you don’t even want to see, what they’re doing, and how advanced they are. We’ll be catching them very shortly. They want to jam transmissions, which threaten our battlefield operations and so many other things. We will be so far ahead of them in a very short period of time, your head will spin. We must have American dominance in space.”

The new NDAA also underscores Defense Secretary James N. Mattis’ shift away from battling terrorist insurgencies and toward the growing threats from Russia and China. For example, it provides $6.3 billion for the European Deterrence Initiative, the largest U.S. expenditure yet for a program aimed at beefing up defenses in European nations near Russia.

House Speaker Paul D. Ryan noted that the legislation calls for a 2.6-percent pay raise for troops in 2019, the biggest in nine years.

“This legislation reforms the Pentagon to make our military more agile, provides resources to ensure our armed forces have the tools needed for modern warfare, and extends funding for global counterterrorism efforts,” said the Wisconsin Republican.

The measure authorizes $7.6 billion for 77 new F-35 “stealth” Joint Strike Fighter jets built by Lockheed Martin, and $24.1 billion to fund the construction of 13 new battle force ships.

Congress named the legislation for Senate Armed Services Committee Chairman John McCain, Arizona Republican, who is battling brain cancer. Mr. Trump, who has feuded with Mr. McCain for most of his presidency, didn’t mention him during his remarks.

Instead, Mr. Trump thanked by name a lengthy list of military chiefs and lawmakers who were in attendance: the commanding general of the 10th Mountain Division, Major General Walt Piatt; the seven members of the Joint Chiefs of Staff, individually; Rep. Elise Stefanik, New York Republican and a member of the House Armed Services Committee in whose district the fort is located; Rep. Don Beyer, Virginia Democrat; Rep. Dan Donovan, New York Republican, Rep. Joe Wilson, South Carolina Republican; and Rep. Martha McSally, Arizona Republican.

The measure authorizes $500 million for the co-development and co-production of missile defense systems with Israel.

Under the new law, $616.9 billion is authorized for the base Pentagon budget in fiscal 2019, which starts Oct. 1. Congress still must complete appropriations to pay for the weapons systems and other military operations

The NDDA authorizes $21.9 billion for nuclear weapons programs under the Energy Department, and another $69 billion to fund U.S. war efforts under the Overseas Contingency Operations account.

The law also bars the U.S. from selling F-35 fighter jets to NATO member Turkey. Last week, Mr. Trump announced he was doubling tariffs on steel and aluminum from Turkey over its plans to purchase a Russian missile defense system.

The administration is also angered by Turkey’s detaining of a U.S. pastor on terrorism charges.

The president said the defense policy measure signals that the U.S. is “on the move once again and we are not backing down.”

“We are the most powerful,” Mr. Trump said. “We are the best funded. We are the biggest, we are the strongest, we are the smartest.”

Fort Drum is home to the legendary 10th Mountain Division. Before his speech, Mr. Trump viewed an air assault exercise on a tarmac at the base, watching as Chinook helicopters delivered howitzers, which were then fired by soldiers.

Mr. Trump told the troops later, “I hate to say this, but nobody stands a chance against you folks.”