Vineyard voters bucked the trend in the hottest contest of the Massachusetts primary on Tuesday, voting overwhelmingly for Robert O’Leary to be the Democratic candidate for Congress.

Mr. O’Leary, the current Cape and Islands state senator, got more than 80 per cent of Democratic votes on the Island — 1,478 of the 1,840 votes cast for 10th district candidate — but that vote was swamped by strong mainland support for his opponent, Norfolk district attorney William R. Keating. District-wide, Mr. Keating scored 51 per cent of the vote.

On the Republican side, Vineyard voters’ preference accorded much more closely with the overall result. About 56 per cent of Island votes went to Jeffrey Davis Perry, a four-term state representative, lawyer and former police officer, compared with 62 per cent districtwide.

Apart from a stronger recognition factor for Mr. O’Leary on the Island, one issue clearly separated him from Mr. Keating: he was the one who supported the proposed Cape Wind development in Nantucket Sound, the only candidate among the four Republicans and two Democrats who did.

The 10th district contest attracted widespread interest among the 13 races on Tuesday, because the district is seen by strategists for both parties as the Republicans’ best chance to pick up a seat in Massachusetts in the Nov. 2 general election.

The seat is without a strong incumbent; after seven terms, Democrat William Delahunt decided earlier this year not to run again.

Massachusetts Republicans were buoyed — and Democrats stunned — by last year’s race for the seat of the late Sen. Edward M. Kennedy, when Republican Scott Brown swept into office over Democrat and state Attorney General Martha Coakley.

An analysis of the turnout for Tuesday’s primaries was ominous for Democrats. Statewide, they have a three to one advantage in registrations, but turnout was only about two to one. In the 10th district race, the number of registered Democrats voting barely exceeded Republicans.

On the Island, turnout was three-to-one Democratic, but most voted for the losing candidate.

Turnout on the Island, as elsewhere in the state, was low: only about 20 per cent.

In his victory speech, Mr. Perry proclaimed himself a “conservative Republican” and a “hardliner on immigration reform” and promised to repeal the health care reform bill.

After a close contest marked by considerable animosity near the end, Mr. Keating extended an olive branch to Senator O’Leary and his supporters, saying they shared similar concerns, and reciting a litany of voter concerns including unemployment, the export of jobs, and Washington politicians who had sold out to big oil.

He also signaled a possible campaign of personal attack, referring again to an incident from Mr. Perry’s police days, in which an officer improperly searched a young woman, allegedly for drugs.

“You stood five steps away as your partner sexually assaulted a young girl,” he said, his voice rising. “If you couldn’t see something so despicable right under your nose, how can we depend on you in Washington?” he said.

For his part, Mr. O’Leary pledged his support to Mr. Keating in advancing their shared policy concerns.

“I believe our positive message — end the war, invest at home; improve our schools and protect the environment — has had an impact on this election, and I hope that it will continue to be a part of the debate about America’s future,” he said in a statement.

In another significant local contest on Tuesday, Dan Wolf, the high-profile head of Cape Air, defeated Sheila R. Lyons, a Barnstable county commissioner, to become the Democratic candidate for the state senate seat being vacated by Mr. O’Leary.

His Republican opponent will be James Crocker, a real estate salesman from Osterville.

For the office of treasurer, Steven Grossman easily defeated Stephen J. Murphy for the Democratic nomination, 61 to 39 per cent, and will face the Republicans’ Karyn E. Polito in November.

In a three-way race for auditor, Suzanne Bump received 50 per cent of the vote to become the Democratic candidate. Republican voters overwhelmingly preferred Mary Connaughton to Kamal Jain, 87 to 13 per cent.

The most hotly contested primary race was for councillor in the first district, with five Democrats and two Republicans contesting. Dukes county commissioner Thomas J. Hallahan of Oak Bluffs won overwhelmingly for the Democrats on-Island, but lost the race on the mainland to Oliver Cipollini of Barnstable.

The Republican primary was won by Mr. Cipollini’s brother, Charles.