U.S. stocks closed sharply lower on Tuesday, erasing earlier gains, as a decline in the broader tech sector brought the major averages down.

The Nasdaq composite fell 2.9 percent to 7,008.81 as shares of Apple and Amazon declined. The pulled back 1.7 percent 2,612.62, with tech sliding 3.5 percent and posting its worst day since Feb. 8. The Dow Jones industrial average closed 344.89 points lower at 23,857.71 and re-entered correction territory, with Microsoft as the worst-performing stock in the index. Earlier in the session, the Dow rose 243 points, while the S&P 500 and Nasdaq also traded higher.

Facebook shares contributed to tech's losses, as they fell 4.9 percent after Bank of America Merrill Lynch reduced its price target on the stock for the second time in five days. The cut comes as Facebook's fallout from the data scandal continues.

Last week, reports emerged alleging that Cambridge Analytica, an analytics company, had gathered data from 50 million Facebook profiles without users' permission. While Facebook has since come out to apologize and try to rectify the matter, concerns remain over data use.

CNN reported Tuesday that Facebook CEO Mark Zuckerberg will testify in front of Congress on the Cambridge Analytica leak.

"While this will not be a pleasant experience for Zuckerberg and his team going in front of Congress, it is a necessary smart strategic step for Facebook to head to the Beltway as the public fury continues to grow around the Cambridge data leak," Daniel Ives, head of technology research at GBH Insights.