President Trump said Monday that he would welcome a lawsuit that former CIA director John Brennan threatened in response to the withdrawal of his security clearance, amid a rare groundswell of opposition to the ­president from hundreds of ex-national security officials who normally steer clear of political disputes.

“I hope John Brennan, the worst CIA Director in our country’s history, brings a lawsuit,” Trump said on Twitter on Monday, a day after Brennan said that he is willing to take the president to court to prevent other current and former officials from having their security clearances revoked.

Trump also has threatened to pull the clearance of Bruce Ohr, a senior Justice Department official, a move that former officials said would amount to an unprecedented attack on career civil servants and mark a significant escalation in the president’s campaign to retaliate against his real and perceived critics.

If Brennan files suit, Trump said, “it will then be very easy to get all of his records, texts, emails and documents to show not only the poor job he did, but how he was involved with the Mueller Rigged Witch Hunt.”

In revoking Brennan’s clearance last week, Trump accused the longtime intelligence officer of abusing his status by criticizing the administration. The president later acknowledged in an interview with the Wall Street Journal that he had moved against Brennan in part because of his role in the beginning of the investigation into whether Trump’s campaign conspired with the Russian government. Special counsel Robert S. Mueller III is now leading that inquiry.

Brennan has long been among Trump’s most vocal critics, questioning his fitness for office and even his loyalty to the United States when he called Trump “treasonous” for his attitude toward Russian President Vladimir Putin at a meeting in Helsinki last month.

But even former officials who would not countenance Brennan’s choice of words have rushed to defend his right to use them. Not since dozens of former national security officials questioned Trump’s credentials during the 2016 campaign have so many from their ranks taken a stand against him, accusing him of an assault on basic democratic values. ​

Trump’s tweet on Monday came as a bipartisan outcry over his revocation of Brennan’s security clearance continued to grow, with the release of a statement of opposition signed by more than 175 people who had held a wide range of national security jobs. Several dozen former CIA officers, as well as former directors who served under presidents of both parties, had signed public letters of opposition.

“Whether people agree with Brennan or not, everyone seems to agree he has a right to speak his mind,” said Nick Shapiro, a former CIA deputy chief of staff and current Brennan spokesman, who signed one of the letters last week.

Trump was said to be relishing the outrage of so many former officials, many of whom, he has told advisers, didn’t vote for him.

“He loves this fight,” a senior White House official said.

Anne Gruner, a former CIA analyst and senior manager who voted for Trump, said she added her name to the list because the president is jeopardizing national security by trying to intimidate current and former officials into silence.

Gruner said that revoking the clearance of an actively serving official such as Ohr could send a particular chill through the national security bureaucracy and might lead analysts not to share important information with the president if they thought it would upset him.

“The cardinal rule for CIA analysts is to ‘speak truth to power.’ But the president’s actions make that riskier,” she said.

Officials have prepared the paperwork to revoke more clearances. But within the White House there were signs that support for the president’s attacks is waning.

Donald McGahn, the White House legal counsel, has expressed some qualms internally about the clearance revocations, and John Bolton, the national security adviser, and John Eisenberg, the legal adviser for the National Security Council, have not been involved in the clearance decisions, according to White House officials who, like others, spoke on the condition of anonymity to discuss internal deliberations.

McGahn has argued that the White House should have a formal process for revoking a clearance, rather than taking action solely at the president’s command and without a specific accusation of violating rules about protecting classified information, the officials said.

White House Chief of Staff John F. Kelly also has expressed concern about revoking more clearances, the officials said.

“There isn’t a lot of support for going past Brennan,” said a senior White House official, who noted particular resistance to pulling Ohr’s because he is a current Justice Department official.

“You can defend Brennan if you watch him on TV and see how out there he is,” one of these people said. “It gets tougher after that.”

Sen. Mark R. Warner (Va.), the ranking Democrat on the Senate Intelligence Committee, introduced legislation Monday that would prohibit federal money from being used to revoke a clearance, except for reasons spelled out in existing regulations. It is unclear whether the measure, which Warner offered as an amendment to a Defense Department spending bill being debated this week, will get a vote.

For former officials, such as Brennan, keeping a security clearance lets them consult with current leaders about national security matters, lending their perspective or explaining how they handled a particular challenge. But it does not give them unfettered access to classified information. As it is for current employees, access is based on the “need to know” about a particular program or operation, experts said.

Trump has alleged that Brennan “leveraged his status as a former high-ranking official with access to highly sensitive information to make a series of unfounded and outrageous allegations — wild outbursts on the Internet and television — about this administration,” according to a statement read last week by the White House press secretary.

Trump also has said that clearances have become moneymakers. He has lately taken aim at Ohr and his wife, a Russia specialist who has done some work for Fusion GPS, the firm behind a dossier on Trump’s Russia ties that has been part of the counterintelligence investigation of Russia and the Trump campaign.

“Will Bruce Ohr, whose family received big money for helping to create the phony, dirty and discredited Dossier, ever be fired from the Jeff Sessions ‘Justice’ Department?” he wrote on Twitter. “A total joke!”

National security experts and lawyers have said that Trump has the power to grant and deny clearances as he sees fit. But in taking away Brennan’s, Trump offered no evidence that Brennan had violated the terms of his lifelong agreements to protect classified information — agreements that bind him as a former CIA officer even if he doesn’t have a clearance.

“The president is using an important tool of national security for political ends, and to punish a critic,” said David S. Cohen, who served as Brennan’s deputy at the CIA. “I think that crosses two lines. It’s the politicization of national security. And it’s an insult to what people in the national security community have dedicated themselves to defend, the right to free expression.”

[To read the list of former national security officials who signed letters of protest about Trump’s revocation of John Brennan’s security clearance, go to: wapo.st/security-clearances]

Felicia Sonmez and Erica Werner contributed to this report.