During the awkward interlude after he was ousted from the speakership but before he resigned from Congress, Kevin McCarthy found himself standing on the House floor one afternoon next to Representative Bob Good of Virginia, one of the eight Republicans who had voted to remove him from power.

“I just traveled to your district,” Mr. McCarthy, still raw over his political downfall, said in what was interpreted as a vaguely threatening tone. “It’s a really nice district.”

“Why don’t you come down and spend money there?” Mr. Good, the chairman of the hard-right House Freedom Caucus, taunted Mr. McCarthy in response.

“Oh, I’m going to,” Mr. McCarthy shot back. “I might spend $5 million there, too.”

In this instance, Mr. McCarthy was as good as his word.

In the months that followed, he helped direct more than $6 million into the race to defeat Mr. Good, who is now fighting to hang on to his seat after coming up 375 votes short in his recent primary against a Trump-backed challenger, John J. McGuire. (Mr. Good’s campaign is paying for a recount, and he is claiming there was “inappropriate activity” at ballot drop boxes in Lynchburg, the district’s biggest city.)

Mr. McCarthy’s campaign to bring down Mr. Good was just one part of an elaborate and expensive campaign of revenge he has mounted since leaving Congress, one designed to ruin the Republicans he holds responsible for his demise.