EU states that support the production of green energy, such as wind and solar power, through subsidies or incentives are not required to support the use of green energy which is produced in another EU country, it said.
The case has political resonance as Europe struggles to wean itself off green energy subsidies, which are blamed for inflating costs and making the European Union less competitive.
The Commission has been pushing for harmonised subsidies across the bloc and encourages cross-border movement of power as part of a single energy market to limit costs and maximise available resources.
The ruling will put less pressure on Germany - which is at odds with the
European Commission over its energy subsidies - to reach a compromise with the Commission.
German economy minister Sigmar Gabriel welcomed Tuesday's ruling.
"The European Court of Justice has sent a clear signal on the continued support of renewable energy in Europe," Gabriel said in a statement.
Read MoreWhat 'war on coal' The carbon fuel is doing fine
The Swedish case arose after Sweden, which offers energy subsidies to companies in Sweden, refused to award them to wind power generated on the Aland archipelago, which lies between Finland and Sweden.
Although it is part of Finland, Aland is connected to Sweden's power grid and it is Swedish-speaking.
Wind energy company Alands Vindkraft in 2009 appealed Sweden's decision on subsidies to the Swedish courts, saying the support scheme violated principles on the free movement of goods.
The case was referred to the ECJ in 2012 and in January this year the court's advocate-general Yves Bot advised that member states be given up to two years to restructure their support schemes to make them compatible with EU law, which would have paved the way for an integrated EU renewable energy market.