After almost 20 years in the making, the world's longest and deepest rail tunnel has officially opened in Switzerland.

The Gotthard base tunnel will provide a high-speed rail link for 57km under the Swiss Alps between northern and southern Europe, the BBC reports.

In a speech to an audience in Erstfeld, situated close to the northern end of the tunnel, Swiss Federal President Johann Schneider-Ammann said it was a giant step for Switzerland, but equally for its neighbours.

The tunnel has overtaken Japan's 53.8km Seikan rail tunnel as the longest in the world and demoted the Channel Tunnel that connects England and France, into third place.

European leaders attended the opening including German chancellor Angela Merkel, French president Francois Hollande, Italy's prime minister Matteo Renzi and Austrian chancellor Christian Kern -- all of whom had great amounts of praise for the tunnel.

All up the project cost around NZ$17.5 billion and resides around 2.3km below the surface of the mountains.

Engineers had to dig through 73 different types of rocks to get to the depth.