WASHINGTON — Andrew Marshall, a Pentagon strategist who helped shape American military thinking on the Soviet Union, China and other global competitors for more than four decades, died on Tuesday in Alexandria, Va. He was 97.

His death was confirmed by Jaymie Durnan, his executor.

Mr. Marshall, as director of the Office of Net Assessment, was the secretive futurist of the Pentagon, a long-range thinker who both prodded and inspired secretaries of defense and high-level policymakers. Virtually unknown among the wider public, he came to be revered inside the Defense Department as a mysterious Yoda-like figure who embodied an exceptionally long institutional memory.

In the early 2000s, at a time when the Pentagon was focused on counterinsurgency and wars in Afghanistan and Iraq, Mr. Marshall urged officials to focus on the challenge of China — a view that many considered outdated. But today, national security officials are increasingly adopting Mr. Marshall’s view of China as a potential strategic adversary, an idea now at the heart of national defense strategy.

Through his many hires and generous Pentagon grants, estimated to total more than $400 million over four decades, Mr. Marshall trained a coterie of experts and strategists in Washington and beyond. One veteran of the office, Air Force Gen. Paul Selva, is now the vice chairman of the Joint Chiefs of Staff. Another, Robert O. Work, was the deputy secretary of defense from 2014 to 2017.