The European Union and Japan have agreed "in principle" on a free trade deal that will affect an overwhelming majority of commerce between the two economic giants and will be officially endorsed at a summit of their leaders Thursday.

EU Council President Donald Tusk and Japanese Prime Minister Shinzo Abe will meet Thursday and will be able to shake hands on the landmark deal, which took four years of negotiations.

EU Trade Commissioner Cecilia Malmstrom said in a Tweet that "We've reached political agreement" and "now recommend to leaders to confirm this" at their short summit.

The timing of the announcement is important, coming just before a summit of world leaders in Hamburg, Germany. U.S. President Donald Trump is expected to express his discontent with free trade and his desire to renegotiate some deals.

Both the EU and Japan have stressed that their pact is intended as a rejection of the kind of protectionism Trump advocates.

For Abe, it shows Japan remains an important partner in global trade, especially after Trump pulled the plug on a trade deal with Pacific nations. For the EU, it shows that it remains a champion of free trade even if free trade negotiations with the United States are in a rut.

A senior EU official, who spoke only on condition of anonymity ahead of Thursday's summit, said that the deal with the Japanese "means we have agreed on almost everything of importance to either side."

Now, legal scrubbing and translations are expected to take several months before the agreement can be formally completed and put to approval to national authorities in the EU and Japan.

The 28-nation EU exports some 86 billion euros in goods and services to Japan every year yet still faces high tariffs and other obstacles in reaching the lucrative market.

A deal would require tweaks to Japan's protections for its dairy farmers, whose home market is protected by tariffs of up to 40 percent on processed cheese, wine, pasta and chocolate.

The EU official said that the EU food agriculture sector was expected to be "the big winner" out of the negotiations.

Japan is specifically looking for removing import tariffs on cars and car parts.