Georgia lawmaker to resign after using racial slurs on new Sacha Baron Cohen show Spencer could have remained in public office through the November election.

A Georgia state legislator handed in his resignation on Tuesday amid fallout over a controversial television appearance in which he exposed himself on camera, used racial epithets and appeared to speak in a mock-Asian accent.

Republican Rep. Jason Spencer caved to mounting pressure for him to step down after an appearance on Sacha Baron Cohen's new Showtime series, "Who Is America?"

"Rep. Jason Spencer has written to Speaker Ralston to announce his resignation from the Georgia House of Representatives effective July 31," a spokesperson for the Georgia House of Representatives told ABC News in a statement Tuesday.

He submitted his resignation via email at around 11 p.m. EST.

Spencer, who lost a primary election in May, could have remained office through the November election.

In the TV episode, which aired Sunday, Spencer is seen using multiple racial slurs, including the N-word, and exposing his bare buttocks while shouting "USA!" and "America!" for what he thought was a counterterrorism video.

Spencer apologized for what he called a "ridiculously ugly episode," but initially refused to step down.

"Sacha Baron Cohen and his associates took advantage of my paralyzing fear that my family would be attacked," Spencer said in a statement. He said he was told that the tactics would deter "what I believed was an inevitable attack."

Cohen posed as an Israeli military expert who convinced Spencer to participate in over-the-top behavior.

Lawmakers on both sides of the aisle had called for Spencer's resignation, and the state's governor, Nathan Deal, said he was "saddened and disgusted" by the video.

"The actions and language used by Jason Spencer are appalling and offensive," Deal said in a statement Monday. "There is no excuse for this type of behavior, ever, and I am saddened and disgusted by it."

Spencer's resignation came just hours after Georgia's secretary of state, Brian Kemp, won the state's Republican nomination for governor on Tuesday, defeating Lt. Gov. Casey Cagle in a runoff election.

Both candidates had urged Spencer to resign.

"Rep. Spencer's words and behavior are hurtful, insensitive, and completely unacceptable. At the very least, he should issue a public apology for this shameful incident," said Kemp, who is backed by President Donald Trump.

Editor's note: Republican Rep. Jason Spencer is a Georgia state legislator. An earlier version of this story incorrectly referred to him as a member of Congress.

ABC News' Briana Montalvo contributed to this story.