U.S. stocks neared records Wednesday on hopes that the United States and Iran are backing away from the edge of war. The rally capped a whirlwind day of reversals that swept through markets. Stocks initially reeled after Iran fired missiles at two bases in Iraq housing US troops, but the selling abated as reports suggested no Americans died and after Iran’s foreign minister said his country had concluded “proportionate measures in self-defense.” Gains accelerated after President Donald Trump said Iran “appears to be standing down.”

On Wednesday:

The S&P 500 rose 15.87 points, or 0.5%, to 3,253.05.

The Dow Jones Industrial Average rose 161.41, or 0.6%, to 28,745.09.

The Nasdaq set a record after rising 60.66, or 0.7%, to 9,129.24.

The Russell 2000 index of smaller company stocks rose 5.29 points, or 0.3%, to 1,663.59.

For the week:

The S&P 500 is up 18.20 points, or 0.6%.

The Dow is down 110.21 points, or 0.4%.

The Nasdaq is up 108.47 points, or 1.2%.

The Russell 2000 is up 2.72 points, or 0.2%.

For the year:

The S&P 500 is up 22.27 points, or 0.7%.

The Dow is up 206.65 points, or 0.7%.

The Nasdaq is up 156.64 points, or 1.7%.

The Russell 2000 is down 4.88 points, or 0.3%.