US stocks ended higher on 21 June following comments by Federal Reserve Chair Janet Yellen and ahead of the much-anticipated Brexit vote on 23 June. Yellen warned that the UK leaving the European Union posed a risk to both the US economy and global financial market stability.

The Dow Jones Industrial Average rose 24.86 points, or 0.1%, to settle at 17,829.73. Gains in the blue-chip gauge were led by a 2.2% rise in Microsoft Corp shares but dragged down by a 0.9% decline in Boeing Co stock, MarketWatch reported.

The S&P 500 gained 5.65 points, or 0.3%, to close at 2,088.90, with energy and telecom shares leading gains. Six of the index's 10 sectors ended in positive territory, while the materials sector led losses among the remaining four.

Meanwhile, the Nasdaq Composite underperformed, falling 6.55 points, or 0.1%, to close at 4,843.76. The iShares Nasdaq Biotechnology ETF (IBB) traded 1% lower.

"The focus of attention this week is on the UK vote on Thursday. It looks like overnight the polls tightened up a little bit," Bruce Bittles, chief investment strategist at Baird, told CNBC. "It's a pretty nervous market. Nobody has any profits for the year. The last thing you want to do is get caught in a downdraft."

A recent Survation poll for spread-betting firm IG revealed the leave camp rallying again to 44% against the 42% from a poll for the Mail. Meanwhile, the Remain camp stayed steady at 45%, CNBC reported. However, a poll from ORB/Daily Telegraph placed the remain camp at 53% and the Leave camp at 46%.

In remarks to the Senate Banking Committee, Yellen warned against the "Leave" camp in the UK referendum and maintained a cautious approach to an interest rate hike.

"Our cautious approach...remains appropriate," Yellen said, according to MarketWatch. CNBC noted that investors are keenly keeping an eye out for clues on the Fed's view on the economy and reasons for its shift away from a June or July rate hike.

Overseas, European and Asian markets closed mostly higher. In Europe, the Euro STOXX 600 closed more than half a percent higher. In Asia, the Nikkei 225 closed more than 1% higher but the Shanghai Composite dropped about a third of a percent.

The US dollar index traded about half a percent higher, with the euro by $1.125 and the yen near 104.8 yen against the greenback. The pound sterling struggled against the dollar and traded around $1.462.

US crude oil futures for July delivery dropped $0.52 (£0.35;€0.46), or 1.05%, to settle at $48.85 (£33.30;€43.42) a barrel. Gold futures for August delivery fell $19.60 (£13.36;€17.42) to $1,272.50 (£867.36;€1,131.16) an ounce.