Shahid Shafi, right, with Texas Gov. Greg Abbott (R) at the Tarrant County Republican Party's Lincoln Day Dinner. (Courtesy of Shahid Shafi) ((Courtesy of Shahid Shafi))

This story has been updated.

The Tarrant County GOP in North Texas voted Thursday to allow its Muslim vice chairman, Shahid Shafi, to keep his leadership position despite a push by a group of Republicans to remove him solely because of his religion. The motion to remove him failed by a vote of 49 to 139, the Texas Tribune reported.

The movement to oust Shafi, a trauma surgeon and Southlake, Tex., city councilman, drew loud condemnation from state leaders over the last several days, including Texas Gov. Greg Abbott, who on Wednesday urged Tarrant County Republicans to remember that “religious freedom is at the core of who we are as a nation and state."

The faction of precinct chairs seeking to oust Shafi believed he couldn’t adequately represent the local Republican Party because his beliefs as a Muslim were incompatible with their politics. In an interview last month, however, Tarrant County’s GOP chairman, Darl Easton, told The Washington Post that he and the majority of the precinct chairs stood in support of Shafi.

“While tonight’s vote brings an end to this unfortunate episode, it also demonstrates we are a Party that respects the right of those who disagree on an issue to have a seat at the table and their voices heard,” Easton wrote in a statement, the Tribune reported. “Religious liberty won tonight, and while that makes a great day for the Republican Party of Tarrant County, that victory also serves notice that we have much work to do unifying our party.”

Shafi talked to The Post about how the movement to oust him affected his and his family’s lives in an interview last month. He said it has been a problem for much of his political career, though never to this extent.

The first time Shahid Shafi ran for a seat on the city council in Southlake, Tex., in 2011, advisers assured him a Muslim in post-9/11 America who spoke with an accent and emigrated from Pakistan would never win an election in Texas.

It’s a story that Shafi, a Republican trauma surgeon, likes to tell because he didn’t believe them. He won the Southlake City Council seat on his second try, in 2014, has since served as a delegate to multiple Texas GOP conventions and, in July, was appointed vice chairman of the Tarrant County Republican Party, located in Fort Worth.

But that’s when his religion somehow became a problem again — in the eyes of some Republican colleagues.

Shafi hadn’t held the position in the North Texas county for more than a couple of days before a precinct chairwoman urged Easton to “reconsider” appointing Shafi to a leadership role, a request that was soon echoed by several other precinct chairs.

“The only reason she had was because he was a Muslim,” Easton told The Post. “That was the only reason she gave.”

That precinct chairwoman, Dorrie O’Brien, and a small group of her supporters later put forth a formal motion to remove Shafi as vice chairman because of his religion, which went up for a vote Thursday. To Easton, who opposed the measure, the motion represents an embarrassment to the Republican Party. And to Shafi, it amounts to exactly what he believed did not exist in the United States when he arrived here 28 years ago: a religious test.

Last month, the Texas GOP Executive Committee passed a formal resolution reaffirming the GOP’s commitment to religious freedom and seeking to distance the party from the xenophobia that it fears the motion against Shafi may embolden. In Texas, it wasn’t the first time Republicans have tried to block Muslims from participating in GOP leadership roles. A Houston City Council staffer attempted, unsuccessfully, to block a Republican Harris County precinct chairman in 2016.

“Let’s show everybody, this is the Republican Party of Texas. We are not the party of bigots,” J.T. Edwards, a member of the State Republican Executive Committee, said last month while urging support for the resolution, the Austin American-Statesman reported.

O’Brien, who declined to speak with The Post, had publicly asserted that Shafi promotes sharia law and is affiliated with terrorist groups while offering no evidence other than that he is a mosque-attending Muslim. In lengthy tirades on Facebook reviewed by The Post, she has accused Shafi of being a “fake Republican” who perhaps became one at the urging of the Muslim Brotherhood so that he could infiltrate the party — again, without any evidence.

“This is, unfortunately, not the first time that people or my political opponents have tried to use my religion against me to distract the voters,” Shafi, who has fiercely denied O’Brien’s assertions, told The Post. “And unfortunately, I don’t think it will be the last either.”

The pleas from state leaders to stop the campaign to remove Shafi appear to have had little bearing on those supporting it. Emails first obtained by the Texas Observer and the Fort Worth Star-Telegram showed O’Brien and fellow Tarrant County Precinct Chairman Dale Attebery inviting John Guandolo, who is described by the Southern Poverty Law Center as an “anti-Muslim activist,” to give a Dec. 29 “training” session on the dangers of sharia law. A former FBI agent, Guandolo has described all Muslims as terrorists during these presentations and has said he believes that American political leaders “should be Christians.”

Attebery, in an email obtained by the Observer and Star-Telegram, said the reason for the class was “because we need to know the truth before Jan. 10,” the date of the vote on Shafi. When asked about the event, Easton stressed that while individual members within the Tarrant County GOP organized it, the party itself does not endorse the session.

“They promote it as, ‘We need to be extremely vigilant of Muslims in this country, particularly the ones running for political office . . . because they’ll take over and start implementing aspects of sharia law that may be counter to U.S. law,’” he said. Easton said he does not expect such an event to sway his support for Shafi and believes that most precinct chairmen will support him as well.

The false generalizations about his religion, Shafi said, have been disheartening and offensive. Born in India but raised in Pakistan, Shafi came to the United States in 1990 to finish his medical degree and surgical residencies before becoming a naturalized citizen in 2009. He joined the Republican Party as a firm believer in small government, having experienced firsthand the oppressive overreach of Pakistan’s leaders. He saw public office as merely an extension of his mission as a surgeon, he said, with the difference being the opportunity to help hundreds or thousands rather than one patient at a time.

“This is my way of giving back to the community that has given me so much,” he said.

Last month, he traveled to the state GOP meeting so that he could be there to answer any questions from those voting on the religious freedom resolution. He was delighted, he said, that he did not have to try to convince them that he was just a regular Republican, free of terrorist ties and focused on lowering property taxes and improving school safety.

They voted 63-0 to pass the resolution — in turn, reaffirming Shafi’s belief in the party, he said.

“I’m not sure if I’ll be able to speak fully without breaking down,” Shafi told the room, the American-Statesman reported.

He revealed that “there were moments of doubt in my mind” over the past six months, as he feared that his own local party might really oust him. The easiest thing he could have done, he told The Post, was resign.

But he didn’t want to, believing it would signal a loss for religious freedom.

“The reason I have stayed on is because the issue before the party is not about who the vice chair should be. It’s much more fundamental than that,” Shafi said. “It is about religious freedom, and if we are going to have a test of religion in the party, where will we stop? If Muslim Americans are not welcome in the GOP, who will be excluded next?”