Foreign-investor money is pouring into the U.S. stock market at the fastest clip in years, ending a long period of selling and providing a fresh boost to a more than eight-year rally.

Overseas buyers have pumped $66.4 billion into U.S. stocks this year through September in their biggest buying spree since 2012, according to the most recently available data compiled by Deutsche Bank. Foreign buying was particularly robust heading into the fall, when investors bought $26.3 billion of stock in September.

This...