New York CNN Business  — 

The Dow recorded its best month of the year in June. It climbed 7.19%, narrowly beating its 7.17% gain in January.

The S&P 500 and the Nasdaq Composite, meanwhile, logged their best months since January, rising 6.9% and 7.4%, respectively. On top of that, the S&P is up 17.4% for the year, marking its best first half since 1997.

The Dow hasn’t done that well in the month of June since 1938, while the S&P recorded its best June since 1955.

In short, it was quite the month for stocks.

Stocks rose in June on hopes that the Federal Reserve will soon cut interest rates to boost the economy. The strong rally has outweighed a few bad days caused by geopolitical and trade worries.

On Friday the Dow (INDU) closed 0.3%, or 73 points, higher, while the S&P (SPX) climbed 0.6% and the Nasdaq (COMP) closed 0.5% up. For the year, the Dow (INDU) is up 14% this year and the Nasdaq (COMP) is 20.7% higher.

At the start of the month, Federal Reserve Chairman Jerome Powell professed his commitment to sustaining economic growth in the United States. The market took that to mean rate cuts are on the horizon — stocks soared in the aftermath of those comments. Lower interest rates typically juice stocks and make it cheaper for companies to borrow money.

The Fed indicated last week that it would cut rates, albeit with somewhat more cautious phrasing. Still, investors are confident that such a move is coming: Expectations for a rate cut in July are at 100%, according to the CME FedWatch tool.

It wasn’t a seamless way to the top for stocks, though.

On June 25, the Dow and the S&P recorded their worst one-day percentage drop in nearly a month.

Tensions between the United States and Iran flared up, after Tehran shot down a US military drone. Iran said the drone entered the country’s territory, while the United States said the incident happened over international airspace. That led to worries about a potential military conflict.

President Donald Trump, meanwhile, dropped his threat of tariffs on Mexico earlier this month. But the United States’ trade war with China is ongoing. Trump and China President Xi Jinping are set to meet on the sidelines of the G20 summit, which has kicked off in Japan. Investors hope the meeting will bring about the next phase of negotiations.