WASHINGTON — The F.B.I. warned a Republican congressman in 2012 that Russian spies were trying to recruit him, officials said, an example of how aggressively Russian agents have tried to influence Washington politics.

The congressman, Dana Rohrabacher of California, has been known for years as one of Moscow’s biggest defenders in Washington and as a vocal opponent of American economic sanctions against Russia. He claims to have lost a drunken arm-wrestling match with the current Russian president, Vladimir V. Putin, in the 1990s. He is one of President Trump’s staunchest allies on Capitol Hill.

As a newly appointed special counsel investigates connections between the Trump campaign and Russian operatives, the warning to Mr. Rohrabacher shows that the F.B.I. has for years viewed Russian spies, sometimes posing as diplomats, as having a hand in Washington.

Mr. Rohrabacher was drawn into the maelstrom this week when The Washington Post reported on an audio recording of Representative Kevin McCarthy of California, the House majority leader, saying last year, “There’s two people I think Putin pays: Rohrabacher and Trump.” Mr. McCarthy said on Wednesday that he had made a joke that landed poorly.

But the F.B.I. has taken seriously the possibility that Russian spies would target American politicians. In a secure room at the Capitol, an F.B.I. agent told Mr. Rohrabacher in 2012 that Russian spies were trying to recruit him as an “agent of influence” — someone the Russian government might be able to use to steer Washington policy making, former officials said.

Mr. Rohrabacher said in a telephone interview on Thursday that the meeting had focused on his contact with one member of the Russian Foreign Ministry, whom he recalled meeting on a trip to Moscow. “They were telling me he had something to do with some kind of Russian intelligence,” Mr. Rohrabacher said. He recalled the F.B.I. agent saying that Moscow “looked at me as someone who could be influenced.”

Law enforcement officials did not think that Mr. Rohrabacher was actively working with Russian intelligence, officials said, rather that he was being targeted as an unwitting player in a Russian effort to gain access in Washington, according to one former American official. The official said there was no evidence that Mr. Rohrabacher was ever paid by the Russians.

Also at the meeting were Representative Mike Rogers, Republican of Michigan, and according to one former official, Representative C. A. Dutch Ruppersberger, Democrat of Maryland. Mr. Rogers and Mr. Ruppersberger were the senior members of the House Intelligence Committee. In a brief telephone interview, Mr. Ruppersberger said that he recalled a meeting with Mr. Rogers and Mr. Rohrabacher, but did not remember that an F.B.I. agent was present. “Mike and I reminded Dana that Russia is our adversary,” he said.

Mr. Rogers, who has since retired from Congress, declined to comment.

Mr. Rohrabacher said he appreciated the warning but needed no reminder. “Any time you meet a Russian member of their Foreign Ministry or the Russian government, you assume those people have something to do with Russian intelligence,” he said.

American intelligence authorities have concluded that Russian spies started a coordinated campaign of hacking and propaganda to damage Hillary Clinton’s presidential campaign and help Mr. Trump. The Justice Department appointed the former F.B.I. director Robert S. Mueller III on Wednesday to lead the investigation into whether Mr. Trump’s campaign colluded in that effort.

Mr. Rohrabacher, like Mr. Trump, has played down the significance of Russian meddling.

“Did they try to influence our election? We have tried to influence their elections, and everybody’s elections,” Mr. Rohrabacher told The Los Angeles Times in March. “The American people are being fed information that would lead them to believe that we need to be in a warlike stance when it comes to Russia.”

Mr. Trump’s presidency has been plagued by questions about his links to Russia. Journalists have uncovered repeated instances of meetings between Trump associates and Russians that were not disclosed or that the White House initially mischaracterized. Mr. Trump’s first national security adviser, Michael T. Flynn, was forced to resign after misrepresenting his conversations with the Russian ambassador.

A federal judge authorized a secret wiretap last year on Carter Page, a foreign policy adviser to Mr. Trump’s campaign, based on evidence that he was acting as a Russian agent. Mr. Page has denied any wrongdoing. American authorities believe that Mr. Page met with a suspected intelligence officer in Russia.

Mr. Rohrabacher, for his part, said he was confident that Mr. Trump’s associates had been savvy in their dealings with Russia. “The president has some very astute people around him,” he said. “I can’t imagine someone in a position of power in the United States government not fully appreciating the fact that whoever he’s dealing with who’s a foreigner that he doesn’t know is trying to influence him.”

Mr. Rohrabacher was already facing what is shaping up to be the most difficult campaign of his 28-year career in Congress — a race some of his colleagues would rather not see him run, given how much money the party may have to spend on his behalf. After largely avoiding difficult re-elections in his Republican-leaning district along a stretch of the Pacific Ocean in Orange County, he finds himself in the Democrats’ cross hairs.

With an increasingly diverse district, which Mrs. Clinton carried last year, and a penchant for provocation, Mr. Rohrabacher has made himself an irresistible target. One well-funded Democrat, Harley Rouda, has already declared his candidacy, and there is talk of other potentially formidable challengers also entering the race.

“It is the strangest thing imaginable in light of what all the intelligence agencies have said about Russia hacking the United States’ electoral process, yet he carries on,” Mr. Rouda said.

As for Mr. McCarthy’s remark, even if only a quip, it showed that Republican leaders were aware enough of Mr. Trump’s Russian links six months before Election Day to joke about them. WikiLeaks had not yet begun to publish hacked emails from the Democratic National Committee or Mrs. Clinton’s campaign chairman. And many of the revelations about Mr. Trump’s associates and their Russian meetings had not yet been revealed.