Rep. Trey Gowdy, who led an investigation into the attack on Americans in Benghazi, Libya, that inadvertently revealed Hillary Clinton's private email server, announced on Twitter Wednesday that he was leaving Congress at the end of his term to return to the justice system.

Gowdy, a congressman from South Carolina and a former prosecutor, said in a tweet that he would not seek re-election to Congress nor to “any other political or elected office; instead I will be returning to the justice system.”

He said that his skills were better used in a courtroom than in Congress and that he enjoyed the justice system more than the political one.

Gowdy, chairman of the select committee on Benghazi, headed the investigation into the 2012 terrorist attack which left U.S. Ambassador Christopher Stevens and three other Americans dead at a U.S. State Department compound in Benghazi.

The final report, released in June 2016, found bureaucratic and inter-agency blunders but no evidence of wrongdoing by former Secretary of State Hillary Clinton. But the panel did discover that Clinton had relied on a private email server while secretary of state, a controversial decision that was damaging to her 2016 campaign for president.

Democrats accused Republicans of using the inquiry, which took more than two years at a cost of an estimated $7 million, to try to hurt Clinton’s chances in the race.

Gowdy, as a member of the House intelligence committee, also has been part of the investigation into Russian meddling in the 2016 election.

NBC News noted that there is an opening on the Fourth Circuit Court of Appeals, which includes jurisdiction over district courts in South Carolina. An appointment to that judgeship would require a presidential nomination and Senate confirmation.

He is among at least 20 Republican incumbents who are retiring this year, adding to the anticipation of Democratic victories in November. Other Republican representatives who have announced they would not seek re-election include Darryl Issa and Ed Royce of California and Rodney Frelinghuysen of New Jersey.

Gowdy was elected in the 2010 tea party surge that returned control of the House to Republicans.

According to his congressional biography, he was a federal prosecutor for six years, handling narcotics trafficking rings, bank robberies, child pornography cases and the murder of a federal witness.

The U.S. Ambassador to the United Nations, Nikki Haley, who was formerly governor of South Carolina, thanked him in a tweet, saying, "I always said that the reason @TGowdySC was amazing at his job was bc he disliked politics so much."