Former FBI Director James Comey said Sunday he will comply with a congressional subpoena from the House Judiciary Committee for a closed-door hearing on the FBI's actions during the 2016 election. Comey initially went to court to fight it.

"Grateful for a fair hearing from judge. Hard to protect my rights without being in contempt, which I don't believe in," Comey said in a tweet. "So will sit in the dark, but Republicans agree I'm free to talk when done and transcript released in 24 hours. This is the closest I can get to public testimony."

A committee aide confirmed Comey will appear before lawmakers this week and the interview will be transcribed. According to his attorney David Kelley, Comey has agreed to sit for a voluntary interview Dec. 7. The committee will give Comey a full transcript of that testimony within 24 hours, which he is free to make public.

Get Breaking News Delivered to Your Inbox

In exchange for agreeing to testify, the committee will drop the subpoena. "Mr. Comey will join us for a closed-door transcribed interview later this week," Committee Chairman Bob Goodlatte said in a statement. "We will release the transcript of his interview to the public as soon as possible after the interview, in the name of our combined desire for transparency."

Goodlatte, a Republican who is retiring, issued the subpoena to Comey the week of Thanksgiving, requiring his testimony in a closed setting during the final weeks of Republican control of the House. Democrats assume control of the majority and subpoena power in the new year.

Comey insisted he would only testify in public, not behind closed doors.

"I've seen enough of their selective leaking and distortion. Let's have a hearing and invite everyone to see," he wrote in a tweet after receiving the subpoena.

Republicans had argued any public hearing with Comey would become a "carnival," as Rep. Trey Gowdy put it.

"The remedy for leaks is not to have a public hearing where you are supposed to ask about 17 months' worth of work in five minutes," Gowdy told "Face the Nation" last Sunday. "I think the remedy is to videotape the deposition. That way, the public can see whether the question was fair. They could judge the entirety of the answer."