Petrobras, as the company is known, said it will appeal the Superior Labor Court's ruling in the case, brought by oil workers seeking more pay.

The ruling points to gathering headwinds for the company, which settled a nearly $3 billion lawsuit with U.S. investors in January and is seeking to cut debt through a $21 billion divestment program.

The case centered around Petrobras' compensation policy since 2007, when it adopted the so-called Minimum Level and Regime Remuneration (RMNR) scheme.

Workers argued that payments tied to special work arrangements, such as night shifts and hazardous work, should be excluded from an agreement on the wage policy.

The ruling could potentially saddle the firm with up to 17 billion reais in added payments.

But Petrobras, backed by the Federal Attorney General's Office, argued that the payments should be included in the base calculation for RMNR, as agreed to in a collective salary agreement with workers.

The head of the Superior Labor Court, Brito Pereira, had to vote to untie the ruling, which had 13 labor judges voting for the employees and 12 for the company.

The change means some 59,000 employees could receive a wage increase of up to 35 percent, according to calculations by the Attorney General's Office.

Petrobras plans to appeal the decision in the Supreme Federal Court, one person with knowledge of the matter said. But the oil giant faces plenty of other headaches.

A nationwide strike by truckers over high fuel costs forced embattled President Michel Temer to cut diesel prices, in part via subsidies paid to Petrobras.

While the cash-strapped government has promised to compensate Petrobras for losses incurred by the price cut, some doubt whether the company will be made whole and the incident drove CEO Pedro Parente to resign.

(Reporting by Ricardo Brito; Editing by Rosalba O'Brien, G Crosse and Bernadette Baum)

By Ricardo Brito