Richard G. Lugar, a six-term Republican senator from Indiana, lost his bid to stay in office after his Tea Party-backed rival questioned his conservative credentials and accused Mr. Lugar of losing touch with Indiana and its voters.

Richard E. Mourdock, the state’s treasurer, defeated Mr. Lugar in the Republican primary on Tuesday, according to networks and The Associated Press. Mr. Mourdock will face Joe Donnelly, a Democratic member of the House, in November.

The results of the primary end the career of one of the longest-serving members of the Senate and provide a new trophy for the Tea Party movement. Mr. Lugar, 80, leaves after three decades as one of the chamber’s leading foreign policy experts and with a reputation as a voice of moderation in his party.

That reputation — and a sense among his constituents that he had long ago become a creature of Washington — doomed Mr. Lugar, who had not faced a primary challenger in more than a quarter-century.

Mr. Mourdock repeatedly accused Mr. Lugar of not being conservative enough for Indiana. He pointed to Mr. Lugar’s votes to confirm President Obama’s Supreme Court nominees, support for immigration legislation known as the Dream Act and his backing of bank bailouts during the economic crisis.

Conservative organizations with connections to the Tea Party movement flocked to Mr. Mourdock, hoping to add to the list of moderate senators they had helped to oust over the past several years. (Bob Bennett, Republican of Utah, and Lisa Murkowski, Republican of Alaska, both lost primary battles to Tea Party candidates, though Ms. Murkowski ran as an independent and kept her seat.)

But Mr. Mourdock also benefited from the perception that Mr. Lugar had long ago abandoned Indiana for a life in Washington. The senator and his wife live in suburban Washington, having sold their house in Indiana years ago.

That became an issue when election officials ruled him ineligible to vote in his former home district. The Marion County election board voted that he no longer meets the residency requirements needed to vote in the county.

That controversy fueled Mr. Mourdock’s case that Mr. Lugar no longer had the interests of Indianans at heart.

The Indiana Democratic Party released a statement Tuesday evening thanking Mr. Lugar for his service and criticizing Mr. Mourdock as an “extremist” who is “out of touch with Hoosiers.”

“Like all Hoosiers, we owe Senator Lugar a debt of gratitude for his long and storied career,” said Dan Parker, the Democratic Party chairman. “Hoosiers deserve real leadership that will reach across the aisle in Richard Lugar’s successor, not Richard Mourdock’s Tea Party extremism.”

After the results were in, Senator Lugar released a statement, defending his decision to run for re-election and criticizing growing partisanship in national politics. “Unfortunately, we have an increasing number of legislators in both parties who have adopted an unrelenting partisan viewpoint. This shows up in countless vote studies that find diminishing intersections between Democrat and Republican positions. Partisans at both ends of the political spectrum are dominating the political debate in our country.”