John Marttila helped shape campaign messages for dozens of Democratic candidates. (Family Photo)

John Marttila, a political consultant who worked on dozens of Democratic campaigns and helped engineer winning electoral strategies for Joe Biden, John F. Kerry, Sen. Edward J. Markey (D-Mass.), former Detroit mayor Coleman Young and dozens of other candidates, died Nov. 3 at a Boston hospital. He was 78.

The cause was complications from prostate cancer, said his son, Doug Marttila.

Mr. Marttila (pronounced mar-TILL-uh) was a onetime Republican who left the GOP in 1970, after Richard M. Nixon became president. “I just couldn’t live with myself,” he said.

In 1970, he left his native Michigan to join the long-shot campaign of the Rev. Robert F. Drinan, a Jesuit priest running for Congress in Massachusetts. Early in the primary race, polls showed that Drinan trailed the incumbent, fellow Democrat Philip J. Philbin by a margin of 40 to 21 percent.

Although many voters considered it improper for a priest to seek political office, Mr. Marttila devised an effective ground strategy, which led to a decisive primary win over Philbin, who had been in Congress for 27 years.

Drinan won the general election as the first Catholic priest elected to Congress and later played a major role in the House of Representatives’ investigation of Nixon during the Watergate scandal. His surprising victory secured Mr. Marttila’s reputation as a political wizard.

John Marttila, right, with John F. Kerry, left, in 1972. (George Butler)

“Politics is common sense and hard work,” Mr. Marttila told the Boston Globe in 1970. “I wouldn’t work on a campaign I couldn’t really believe in.”

In 1972, he was the architect of Biden’s first election to the Senate and managed Kerry’s unsuccessful campaign for the House of Representatives.

“John was the general,” Kerry said Saturday in an interview with The Washington Post. “He helped to change American politics and the times. He was an instrument of transformation.”

Mr. Marttila and his political consulting company were soon in demand throughout the country. He was among the first political strategists to take advantage of new technologies, including computers and sophisticated polling methods. In a four-year period, Mr. Marttila’s candidates won 17 of 20 contests.

“We hit as a team, with experts in each field,” Mr. Marttila told the New York Times in 1974. “It’s not deceptive, it’s very fundamental. Managing a campaign is making rational decisions.”

His methods were crucial to Biden’s victory in Delaware in 1972. At the time, Biden was 29, and his political experience consisted of two years on the New Castle County council. His opponent was a two-term Republican senator, J. Caleb Boggs, who had almost a 30-point lead in the polls in August.

Mr. Marttila saw an opening because Boggs was “on both sides of every issue,” Mr. Marttila told The Post at the time. “As a consequence, there’s no clear impression of Boggs. He doesn’t have those hard edges a guy really needs to have.”

Biden may have been young and untested, but Mr. Marttila saw that “Joe makes a very, very good impression when he’s campaigning.”

Biden embarked on a shoe-leather campaign, meeting voters face-to-face and listening to their complaints. In one ad, Biden talked to people at a shopping mall, asking them: “Do you believe politicians when they tell you something in an election year?”

The answers generally ranged from “not particularly” to “definitely not.”

Biden’s closing words in the ad struck a chord: “That’s what we’ve come to. Politicians have done such a job on the people that the people don’t believe them anymore, and I’d like a shot at changing that.”

Biden served six terms in the Senate before becoming President Barack Obama’s vice president.

In 1976, Mr. Marttila was instrumental in sending another Democrat to Congress for the first time. That year, Markey was a member of the Massachusetts legislature and was sponsoring a bill to prohibit judges from having private law practices on the side.

The measure was unpopular with leaders of Markey’s own party, and he was booted off the judiciary committee of the Massachusetts House of Representatives. His desk was moved to a hallway.

During the primary race against 11 other candidates, Mr. Marttila and his team came up with Markey’s campaign slogan: “The bosses can tell me where to sit. No one can tell me where to stand.”

Markey won the primary and the election and went on to serve 37 years in the House before joining the Senate in 2013.

“He devised a way to get me out of a 12-way race and into a decisive lead,” Markey said of Mr. Marttila on Saturday. “He had a mastery of political issues and strategies. He provided the kind of insights that could only come from a political genius.”

John Phillip Marttila was born Oct. 18, 1940, in Detroit. His father worked in an auto factory, and his mother was a homemaker.

Mr. Marttila graduated from Detroit’s Wayne State University in 1963, then briefly attended law school at Wayne State before leaving to work as a political organizer. He helped recruit African American voters for the Republican Party in Detroit before switching his allegiance to the Democrats.

Over the years, he worked on the successful mayoral campaigns of Young in Detroit, Kevin H. White in Boston and Ernest N. “Dutch” Morial in New Orleans. In 1982, he dropped then-D.C. Mayor Marion Barry as a client when Barry failed to take his advice.

His other clients included the late senator Thomas F. Eagleton (D-Mo.), former congressman Barney Frank (D-Mass.), the late senator Edward M. Kennedy (D-Mass.) and Michael S. Dukakis, the 1988 Democratic presidential nominee and former Massachusetts governor.

Mr. Marttila also worked to advance many ballot measures and other initiatives and conducted extensive polling about U.S. attitudes toward Russia.

His marriage to Nancy Watchko ended in divorce, but she helped care for him near the end of his life. Survivors include two children, Doug Marttila and Katherine Marttila, both of Somerville, Mass.; and two granddaughters.

“People had an inherent respect for John,” Kerry said. “He insisted on trying to win by doing the right thing. He was what America needs and wants in its politics.”

An earlier version of this story incorrectly stated that John F. Kerry won his campaign for the House of Representatives in 1972. He won the primary but lost the general election.