The London Stock Exchange and German rival Deutsche Borse have reached a deal on a £21billion merger to create one of the biggest exchange companies in the world.

Billed as a “merger of equals”, the deal will see the LSE make up 45.6% of the joint firm and Deutsche Borse the remaining 54.4%.

Xavier Rolet, chief executive of London Stock Exchange Group, said: “We are creating an industry-defining combination which will be a leading global market infrastructure business.”

The two companies announced they were in talks last month, but since then there has been the threat of the deal being gatecrashed after the owner of the New York Stock Exchange said it was considering a rival bid for the LSE.

Intercontinental Exchange confirmed it was mulling a possible offer earlier this month, while Chicago’s CME Group was also reportedly considering entering the fray.

Under the merger plans, the combined LSE and Deutsche Borse will maintain headquarters in London and Frankfurt, while it will also be listed on the LSE and Frankfurt Stock Exchange. However, the as-yet-unnamed group will be domiciled in the UK for tax purposes.

The groups said the deal will “bring together” the might of London as one of the world’s biggest financial centres and Frankfurt - the home of the European Central Bank with access to Europe’s largest economy.

Carsten Kengeter, chief executive of Deutsche Borse, said: “It is the logical evolution for our companies in a fundamentally changing industry.

“As a combined group we will create a European player that will compete on a global basis.”

The agreed all-share deal will see Mr Rolet step down, with Mr Kengeter becoming chief executive of the combined company and LSE’s Donald Brydon taking up the role of chairman.

The current chairman of Deutsche Borse, Joachim Faber, would become deputy chairman and senior independent director, with LSE’s David Warren retaining his position as chief financial officer.

On stepping down, Mr Rolet will be retained as an adviser to the chairman and deputy chairman to help with a smooth handover, a post he is likely to hold for up to a year.

The bourses reiterated warnings over the impact of a vote for the UK to leave the EU and said they have set up a referendum committee.

They said a Brexit could “affect the volume or nature of the business carried out by the combined group”, but added that the merger is “well positioned to serve global customers irrespective of the outcome of the vote”.

Details of the deal also revealed aims to save 450million euros (£353m) a year following the merger, which is set to complete by the end of this year or the first quarter of 2017.

It marks the third attempt by the pair to merge after previous moves failed in 2000 and 2004-5 when talks collapsed.