WASHINGTON — A divided Supreme Court ruled today that debt collection companies can’t be sued for trying to recover years-old credit card debt from people who seek bankruptcy protection.

The 5-3 ruling is a blow to consumer groups that complain debt collectors are unfairly misleading people into repaying old debts even when they are not required to under the law.

The court sided with Midland Funding, which was trying to collect $1,879 in debt an Alabama woman had incurred more than 10 years earlier. Aleida Johnson argued that Midland was wrong to go after the debt because Alabama law has a six-year statute of limitations for a creditor to collect overdue payments.

While Johnson ultimately avoided paying the debt, a federal appeals court said she could sue Midland for trying to collect it as a violation the Fair Debt Collection Practices Act.

That law prohibits collection companies from making a “false, deceptive or misleading representation” or trying to recover debt through “unfair or unconscionable means.”

Writing for the majority, Justice Stephen G. Breyer broke with his liberal colleagues to say efforts to recoup old debt during the bankruptcy process do not violate the law. He said it wasn’t false or misleading because bankruptcy law technically allows such claims.

And Breyer said it wasn’t unfair or unconscionable since a bankruptcy trustee can object to any claims that are so old they don’t have to be repaid. That’s what happened in Johnson’s case, and Breyer said that reduces any concern that consumers might unwittingly pay a debt that is too old.

Breyer’s opinion was joined by Chief Justice John G. Roberts Jr. and Justices Anthony M. Kennedy, Clarence Thomas and Samuel A. Alito Jr.

In dissent, Justice Sonia M. Sotomayor said the practice “is both unfair and unconscionable.”

“Professional debt collectors have built a business out of buying stale debt, filing claims in bankruptcy proceedings to collect it and hoping that no one notices that the debt is too old to be enforced by the courts,” Sotomayor said.

Her dissent was joined by Justices Ruth Bader Ginsburg and Elena Kagan.

Justice Neil Gorsuch did not participate in the case.