FRANKFURT—A German court ruled on Friday that Austria’s Heta Asset Resolution AG, the “bad bank” of failed Austrian lender Hypo-Alpe-Adria International Group AG, must pay billions of euros to Germany’s BayernLB, a bank controlled by the state of Bavaria.

The regional court in Munich said Heta, which is controlled by the Austrian government, must pay back loans to BayernLB, a victory in BayernLB’s attempt to recoup €2.35 billion...