Wall Street ended a wobbly week with broad gains Friday, closing the books on June with its biggest monthly gain since January.

June marked a sharp about-face from May, when traders fled to safer holdings because of increased anxiety over the trade war between the U.S. and China, and signs of slowing global economic growth.

Despite lingering worries over trade, investors pushed stocks higher for much of this month after the Federal Reserve raised expectations that it is prepared to cut interest rates if needed to keep the economy growing. That drove the benchmark S&P 500 to an all-time high last week, though it has retreated slightly from that mark.

Even after the roller-coaster quarter, investors are in good shape so far this year. The S&P 500 is up 17.3% and the technology-heavy Nasdaq has gained 20.7%.

"It hasn't been maybe as healthy a rally as we saw in the first (quarter)," said Brian Nick, chief investment strategist at Nuveen. "When you look back 10 years from now it's not going to look like the sort of volatile period where we had this good April, terrible May, and good June. It's just going to look like a quarter where you know you made money in stocks, you made money in bonds."

On Friday, the S&P 500 index rose 16.84 points, or 0.6%, to 2,941.76. The index ended the month with a 6.9% gain.

The Dow Jones Industrial Average gained 73.38 points, or 0.3%, to 26,599.96. The Nasdaq composite rose 38.49 points, or 0.5%, to 8,006.24.

Smaller company stocks were big gainers for the second straight day. The Russell 2000 index climbed 20.02 points, or 1.3%, to 1,566.57.

Every major index finished the week with a loss, but ended June with solid gains.

Bond prices were little changed. The yield on the 10-year Treasury note held at 2%.

The market ended the final week of June with a two-day winning streak. A wave of selling swept over the market earlier in the week as traders shifted money to less risky holdings like U.S. government bonds while remaining cautiously optimistic about this weekend's meeting between President Donald Trump and President Xi Jinping of China.

The meeting, set to take place in Japan, will mark the first time the two leaders meet since the trade war escalated following 11 rounds of negotiations.

Investors are hoping the talks put the world's two biggest economies on track to resolve their trade dispute, which has led to costly tariffs imposed by both countries on each other's goods. Wall Street is worried the fallout from the tariffs could hurt global economic growth and corporate profits. The dispute has prompted the Federal Reserve to say it is willing to cut interest rates if the dispute hurts the U.S. economy.

"Investors need to recognize that the trade situation is unlikely to improve," said Kristina Hooper, chief global market strategist at Invesco. "The best we can hope for is an agreement to continue talks."

Banks led the way higher Friday after the Federal Reserve late Thursday approved plans by the country's 18 biggest banks to return more money to shareholders. The approvals were part of the Fed's annual checkup of the banking system. JPMorgan Chase rose 2.7% and Bank of America climbed 2.8%.

Industrial and energy stocks also notched strong gains. Union Pacific rose 1.9% while oil companies including Chevron and Exxon rose.

Constellation Brands climbed 4.6% after the wine and beer company raised its profit forecast for the year following a blowout fiscal first quarter financial report. Constellation recently sold some of its lower-end wines as it focuses more on its premium wine options and its beer sales.

Secondhand-fashion online retailer RealReal jumped on its first day of trading. The company, which offers a marketplace for discounted Gucci and other luxury goods, surged 44.5% after its IPO hit the market at $20 per share.

Major stock indexes in Europe rose, while energy futures closed mostly lower.

Benchmark crude oil fell 96 cents to settle at $58.47 a barrel. Brent crude, the international standard, held steady at $66.55 a barrel. Wholesale gasoline slid 3 cents to $1.92 per gallon. Heating oil declined 2 cents to $1.93 per gallon. Natural gas fell 1 cent to $2.31 per 1,000 cubic feet.

Gold rose $1.30 to $1,409.70 per ounce, silver added 5 cents to $15.25 per ounce and copper was unchanged at $2.71 per pound.

The dollar rose to 107.78 Japanese yen from 107.76 yen on Thursday. The euro strengthened to $1.1378 from $1.1373.

___

AP Business Writer Damian J. Troise contributed to this report.

Copyright 2019 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.