But calling himself a “moderate,” he supported many conservative ideas. He voted in his first Senate term for a constitutional amendment to require balanced federal budgets, and for President Ronald Reagan’s nuclear buildup and sale of early-warning Awacs planes to Saudi Arabia. He was also a strong ally of Montana’s timber, oil and gas interests.
As Senator Melcher ran for re-election in 1982, the far-right John Birch Society gave him a 63 percent favorable rating, fifth highest among Senate Democrats. Many Democratic voters grumbled over his conservative leanings. President Reagan went to Montana to campaign for Larry Williams, the Republican candidate, but Dr. Melcher was narrowly re-elected.
In 1988, with Montana’s economy down in a recession and polls showing voters leaning toward conservative solutions, Dr. Melcher, running for a third term, seemed eager to avoid being tagged a liberal: He noted that he opposed abortion and backed prayers in public schools. Conrad Burns, his Republican challenger, called him “soft on drugs, soft on defense and very high on social programs.”
In an upset, Dr. Melcher lost by 13,000 votes out of 357,000 cast, and was the Senate’s only Democratic incumbent turned out of office that year. He tried to reclaim the seat in 1994 but was defeated in the Democratic primary by Jack Mudd, a former law school dean. Mr. Mudd then lost the general election to Mr. Burns, who won a second term.
John David Melcher was born in Sioux City, Iowa, on Sept. 6, 1924, one of three sons of Anthony Melcher and the former Nell Mentor. His parents were divorced when John was 8, and he and his brother, Robert, stayed with relatives when their father, a traveling salesman of farm pumps, went on the road. Another brother, Patrick, had died earlier.
John grew up in Dubuque and Ashton, Iowa, and on a ranch 10 miles outside Oelrichs, S.D. Members of his family recalled that he rode a horse to and from Oelrichs High School, from which he graduated in 1942.
On summer vacations, John sometimes accompanied his father on business trips, and on one journey to the West he fell in love with the prairies and mountains of Montana.
He attended the University of Minnesota for a year, but left to join the Army in World War II. He served with the 76th Infantry Division in Europe and participated in the invasion of Normandy in 1944. Wounded near Trier, Germany, in 1945, he won the Purple Heart, the Combat Infantryman’s Badge and the Bronze Star. He was discharged and hospitalized at Santa Barbara, Calif.
After recuperating in late 1945, he married Ruth Klein, a former high school classmate. They had six children.
Besides his daughter Joan, Mr. Melcher is survived by two other daughters, Teresa Thompson and Mary Melcher; his sons, Robert and John; a brother, Robert; a half sister, Virginia DiNovis; a half brother, Thomas Melcher; 10 grandchildren and five great-grandchildren. His wife died in 2015. Another son, David, died of Reye’s syndrome at 6.
Dr. Melcher earned a degree in veterinary medicine from Iowa State University at Ames in 1950. Drawn by memories of a childhood trip with his father, he moved with his family to Forsyth, a community of under 2,000 in eastern Montana. There he established his Yellowstone Veterinary Clinic and treated horses, cattle, pigs and sheep until his election to Congress in 1969.
In 1953, he was elected to the Forsyth City Council. Finding a liking and a talent for public service, he won a string of elections, and served as Forsyth’s mayor from 1955 to 1961, as a member of the Montana House of Representatives from Rosebud County from 1961 to 1963, and as a state senator in Helena, the capital, from 1963 to 1967.
He then returned to the lower house for two years, but with encouragement from Democratic and legislative colleagues he had his sights set on the national stage. He was a square-jawed, down-to-earth politician whose interests in animals and agriculture grew out of long associations with farmers, ranchers and small-town people in sparsely populated eastern Montana.
Dr. Melcher lost his initial race for a seat in Congress in 1966. But in 1969 he won a special election to replace Representative James F. Battin, a Republican who had resigned to take a federal judgeship.
Dr. Melcher settled in Missoula after his years in Washington. He founded a lobbying and consulting firm and worked for the Association of American Veterinary Medical Colleges and for various veterinary medical groups for many years.
In an interview for this obituary in 2017, Dr. Melcher recalled his 1984 amendment to the Animal Welfare Act of 1966, requiring that the psychological well-being of nonhuman primates be considered in research.
“It was just something I could do,” he said of his measure, which prohibited long periods of isolation in cages and other mental cruelties.
Jane Goodall, the primatologist and authority on chimpanzees, hailed his amendment. She visited Dr. Melcher in Washington, gave him a copy of her book “The Chimpanzees of Gombe” (1986) and wrote in an inscription: “When this bill is well and truly implemented, the difference in the lives of hundreds of animals will truly be great.”