By Alexander Osipovich And Anna Isaac

U.S. stocks wrapped up their best month since April, continuing an extraordinary rally fueled by stimulus from Washington, signs of economic revival and progress toward a coronavirus vaccine.

All three major U.S. stock indexes have climbed for five consecutive months after a brutal February and March that ended the longest bull market on record. The benchmark S&P 500 has surged 35% over that period, its largest five-month percentage gain since 1938.

The index advanced 7% for the month -- its best August since 1986 -- but ended on a downbeat note, falling 7.70 points, or 0.2%, to 3500.31 on Monday.

The S&P 500 set records last week after the Federal Reserve signaled that it was likely to keep U.S. borrowing costs low for an extended period. Meanwhile, recent economic data, including July's orders for durable goods, have surpassed economists' expectations. The index is up 8.3% in 2020.

"They've confirmed lower-for-longer rates as far as the eye can see," said Richard Dunbar, head of multiasset research at Aberdeen Standard Investments. "Alongside that confirmation of cheap money and cheap discount rates, we've just come through a U.S. earnings season that's been a lot better than feared."

Still, some investors are bracing for a potential reversal in September. U.S. lawmakers are scheduled to return to work following an August recess and could resume talks to end the gridlock on a new coronavirus stimulus package as November election campaigns go into full swing. A failure by Congress to deliver additional relief measures for American consumers and businesses could weigh on market sentiment.

"There's uncertainty about future support," Mr. Dunbar said. "Investors are nervous generally, and keen to see support continue through low interest rates and fiscal policy. Any discussion of that being disrupted can make investors nervous."

The Dow Jones Industrial Average and the technology-heavy Nasdaq Composite posted respective monthly gains of 7.6% and 9.6%, their best performances since April. The Dow is still 3.8% below February's record and is off 0.4% for the year, while the Nasdaq closed at another record Monday, extending its gains for 2020 to 31%.

Investors have also gained hope that the world will overcome the Covid-19 pandemic thanks to upbeat news about multiple vaccines in various stages of testing. Among the most advanced candidates are one being developed by the University of Oxford and AstraZeneca. Pfizer, with its partner BioNTech, and Moderna also have experimental shots that have shown promise.

Fed Chairman Jerome Powell helped buoy investor optimism last week by announcing a shift in the central bank's approach to monetary policy, which eliminated any concerns that the Fed might ratchet up rates to combat inflation anytime soon.

A top Fed official affirmed the U.S. central bank's new stance in a speech on Monday. Vice Chairman Richard Clarida said the Fed shouldn't tighten monetary policy just because of low unemployment and cast doubt on economic models that the Fed used in the past to justify raising interest rates.

The tech sector of the S&P 500 led the way in August as it has for much of the year, ending the month up 12%.

That was followed closely by the consumer-discretionary group -- home to Amazon.com Inc. -- and the communications services segment -- which includes Facebook Inc. and Google parent Alphabet Inc. Both groups rose more than 9%. The only sectors to finish August in the red were utilities, energy and real estate.

Among the best performing stocks in August were Royal Caribbean Group and MGM Resorts International, both up about 40%. The two travel-and-leisure stocks were pummeled during the pandemic and are still off by double-digits on a percentage basis in 2020.

Business-software provider Salesforce.com Inc. joined those stocks at the top of the S&P 500's leaderboard, buoyed by last week's robust earnings report and its inclusion Monday in the Dow Jones Industrial Average. Shares rose 40% in August, extending their 2020 gains to 68%.

During Monday's session, Apple shares rose 3.4%, extending their 2020 gains to 76%, after the company's 4-for-1 stock split took effect. Tesla shares, which have quintupled this year, jumped 13% after the electric-car maker's 5-for-1 split. Stock splits, which have been less common in recent years, often result in a bounce in a company's stock price.

Going into the autumn, the strength of the economic recovery may be tested if the number of new coronavirus infections in the U.S. and Europe increases and prompts fresh restrictions on business activity.

"Basically for the U.S. market, we are at a key resistance level," said Nadège Dufossé, head of cross-asset strategy and deputy global head of multiasset allocation at Candriam. "If the market continues to turn more positive, it will benefit value; European and emerging markets' stocks will benefit as investors look beyond the U.S. for returns."

Investors are also braced for a surge in volatility stemming from any uncertainty or dispute about the results of the U.S. presidential election.

"We have a pretty big disparity between the two candidates and the two potential administrations," said Jason Pride, chief investment officer of private wealth at Glenmede. He noted that futures on the Cboe Volatility Index are elevated in the period around November, to a greater degree than in past presidential elections -- an indication that traders are betting on volatility around the vote.

"The market is basically saying that this is a big election," he said.

Write to Alexander Osipovich at alexander.osipovich@dowjones.com and Anna Isaac at anna.isaac@wsj.com