Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

LOS ANGELES — Judge Stephen Reinhardt, a liberal stalwart on the U.S. 9th Circuit Court of Appeals for nearly four decades, died Thursday in Southern California. He was 87.

Reinhardt died of a heart attack during a visit to a dermatologist in Los Angeles, court spokesman David Madden said.

"As a judge, he was deeply principled, fiercely passionate about the law and fearless in his decisions," 9th Circuit Chief Judge Sidney Thomas said in a statement. "He will be remembered as one of the giants of the federal bench."

Reinhardt, shown in a 1997 file photo, was the sixth longest-serving judge on the court. Stephanie Turner / AP

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Reinhardt was appointed by President Jimmy Carter in 1979 and went on to become the sixth longest-serving judge on the court.

He was considered to be one of the most liberal judges on the 9th Circuit and his rulings often placed him on the side of immigrants and prisoners. Reinhardt wrote a 2012 opinion striking down California's gay marriage ban.

He also wrote a 1996 opinion that struck down a Washington state law that prohibited doctors from prescribing medication to help terminally ill patients die.

Last year he wrote in an opinion that a Trump administration order to deport a man who entered the country illegally nearly three decades ago and became a respected businessman in Hawaii was "inhumane" and "contrary to the values of the country and its legal system."

"He was a giant — not just on the 9th Circuit, but within the law," University of California, Berkeley, law school Dean Erwin Chemerinsky told the Los Angeles Times. "He also was a judge with a particular vision of the law, based on enforcing the Constitution to protect people."

Reinhardt joined another judge in ruling that the words "under God" in the Pledge of Allegiance were unconstitutional, a decision that was later overturned.

He was among the federal judges who decided that overcrowding in California's prison system was unconstitutional.

A New York-native, Reinhardt was a graduate of Southern California's Pomona College and earned his law degree at Yale Law School.

After serving two years in the U.S. Air Force, he served as a clerk for a federal judge in the District of Columbia, then entered private practice in Los Angeles. He served as an informal adviser to Los Angeles Mayor Tom Bradley and served on the city's Police Commission from 1975 until his appointment to the 9th Circuit.

Reinhardt is survived by his wife, Ramona Ripston, the former director of the American Civil Liberties Union of Southern California.