ROME, June 27 (Reuters) - Italy's Constitutional Court ruled on Thursday that part of a 2022 windfall tax weighing on energy companies is unlawful, in a move that could hit Rome's strained public finances.

The ruling paves the way for firms to demand partial refunds and limits the scope for similar taxes in the future, according to two sources familiar with the matter.

Former Prime Minister Mario Draghi introduced a one-off levy in 2022 that allowed the Treasury to collect 2.8 billion euros ($2.99 billion), despite criticism and refusals to pay from numerous companies.

The levy was unlawful because it included excise duties in the tax base that companies were forced to use to calculate the sums to be paid, according to the ruling.

One of the sources said the impact on public finance may be limited because the Treasury will be able to offset any refunds with sums collected from companies that have still not paid the levy.

Italy's 2023 budget deficit came in at 7.4% of GDP, the highest in the euro zone. Rome plans to bring the fiscal gap below the EU's 3% limit only in 2026.

($1 = 0.9350 euros) (Reporting by Giuseppe Fonte, editing by Gavin Jones)