BRUSSELS (Reuters) - The European Union's top court should set aside a judgment invalidating a farm trade accord between the EU and Morocco, an adviser to the court said on Tuesday, offering a potential resolution to a diplomatic clash between the two.

The General Court of the European Union, the EU's second-highest court, ruled in December that the trade deal was void after a suit filed by the Polisario Front, which wants independence for the disputed territory of Western Sahara.

The court held that the EU had failed to examine whether a deal would affect the exploitation of natural resources in the Moroccan-controlled territory. That ruling prompted Morocco to suspend contact with EU institutions for four weeks and the EU to lodge a legal appeal.

Advocate General Melchior Wathelet said on Tuesday that Western Sahara was not part of Morocco so neither the 2000 EU-Morocco Association Agreement nor the 2012 EU-Morocco Agreement on liberalization of trade in agricultural and fishery products applied to the territory.

If the trade agreements were declared valid by the European Court of Justice, the EU and Morocco should avoid a repeat of the diplomatic clash at the start of this year.

Opinions by the advocate general are not binding, but EU court judges follow them in the majority of cases.

The EU and Morocco have struck agreements allowing duty-free quotas for agricultural products such as tomatoes and granting access for European vessels to fish in Moroccan waters in return for financial assistance. The two sides also began negotiations in 2013 to form a deeper and broader free trade agreement.

Morocco has controlled most of Western Sahara since 1975 and claims sovereignty over the sparsely populated stretch of desert to its south, which has offshore fishing as well as phosphate and possibly oil reserves.

But its annexation of the region led to a rebellion by the Polisario Front backed by Morocco's neighbor Algeria. The Front and Morocco have been at loggerheads ever since.

(Reporting By Philip Blenkinsop, editing by Robin Emmott)