By Michael Wursthorn and Joe Wallace

U.S. stocks ended the week roughly where they started, leaving the S&P 500 hovering just below its February record and a remarkable rally stuck in neutral.

The broad index closed flat Friday after bobbing between small gains and losses for most of the session, the latest in a series of modest moves that left the S&P 500 up 0.6% from where it was a week earlier.

The S&P 500 attempted several runs this week at a new high, which would have erased the losses suffered during the coronavirus pandemic and marked its fastest-ever recovery from a bear market. But the index repeatedly fell short.

The market's trepidation reflects the uncertainty facing investors and the country as coronavirus cases and deaths continue to rise, analysts said. The main sticking point that has dogged markets lately is the continuing haggling between lawmakers over additional aid to help the unemployed.

Fresh economic data, including unemployment claims and retail spending, continue to suggest the economy is recovering, albeit slowly. Whether the recovery can persist in the absence of further stimulus is something investors are weighing now, analysts added.

Despite those concerns, stocks are trading near their highest levels ever, stretching valuations to a point that haven't been seen since the dot-com bubble. Tech stocks, which have driven much of the stock market's recovery, are even pricier and have traded sideways all week.

"There's a lot of confusion out there," said Larry Swedroe, chief research officer at Buckingham Wealth Partners, of his conversations with investors in recent weeks. "They ask how could stock prices be so high when we're going through this terrible crisis."

Not helping matters is the looming November election, which is less than three months away. Former Vice President Joe Biden named his running mate, Sen. Kamala Harris, on Tuesday, clarifying the Democratic presidential ticket. Several investors said they expect to see some election-induced volatility as November nears, particularly if Democrats appear likely to fare well. That would raise the likelihood of higher corporate taxes and regulation in 2021.

"The risk of a Biden win could have big, negative implications for the market," said Mr. Swedroe, although he added trade tensions between the U.S. and China would likely improve in that scenario.

On Friday, the S&P 500 fell less than a point to 3372.85, leaving it 0.4% away from its Feb. 19 record. The Dow Jones Industrial Average added 34.30 points, or 0.1%, to 27931.02, finishing the week up 1.8%.

The Nasdaq Composite fell 23.20 points, or 0.2%, to 11019.30 after Apple, Facebook and Amazon.com all notched small losses. The tech-heavy index ended the week relatively unchanged.

Industrial and energy stocks scored the biggest gains of the day, rising 0.4% and 0.9%, respectively. But without the participation of tech stocks, which are particularly influential in the index, the S&P gained little traction throughout Friday's session.

Money managers are also awaiting trade talks between senior U.S. and Chinese officials, scheduled for Saturday. Relations have deteriorated in recent months, concerning investors who think fresh barriers to trade would further hurt the global economy.

The main thrust of the discussion is aimed at evaluating China's compliance with a bilateral trade agreement signed in January. Chinese Vice Premier Liu He, President Xi Jinping's chief trade negotiator with Washington, is expected to bring up concerns over the executive orders against the WeChat and TikTok apps.

"The tone of these talks will be crucial," said Jane Foley, head of foreign-exchange strategy at Rabobank. "There is a concern that China has perhaps not fulfilled its promises in, for example, importing agricultural or energy goods from the U.S."

Several retailers are also expected to report quarterly results next week, giving investors additional windows into consumer activity. Walmart, Home Depot and Kohl's are due to disclose results Tuesday, while TJX and L Brands follow later in the week.

Write to Michael Wursthorn at Michael.Wursthorn@wsj.com and Joe Wallace at Joe.Wallace@wsj.com