Shortly after the announcement on Wednesday, German logistics billionaire Klaus-Michael Kuehne said he was considering a counter offer for HHLA, the company that runs the port. HHLA shares surged 45% to a 19-month high.

Switzerland-based MSC and the city of Hamburg said they agreed a deal in which MSC will make a cash offer of 16.75 euros ($17.99) per share to acquire all listed class A stock in HHLA.

That is well above Tuesday's closing share price of 11.54 euros and, if the offer is taken up in full, would give MSC a 49.9% stake in HHLA at a cost of about 1.26 billion euros

The city of Hamburg, which currently owns 69% of HHLA's A shares and all of its unlisted S-shares, would hold 50.1% via the S-shares.

"We must maintain a majority, we must retain influence," Hamburg's finance senator, Andreas Dressel, said at a press conference announcing the agreement.

MSC CEO Soren Toft said that the number of Hamburg-based MSC jobs would be doubled to more than 700.

Kuehne, who owns a stake in shipping group Hapag-Lloyd, said he was considering a counter offer.

"First access to a minority stake in HHLA should of course have been granted to a genuine Hamburg company like Hapag-Lloyd," he told German newspaper FAZ.

"I can only strongly advise Hapag-Lloyd to make a takeover bid for 49.9% of HHLA shares itself and immediately," he said, adding that if this did not occur, his own holding company would consider doing so

Hapag-Lloyd did not comment on a potential takeover bid, saying only the deal would "not affect our cooperation with HHLA". A company source told Reuters that the fact Hapag-Lloyd would essentially be paying terminal fees to its biggest competitor under the deal was an "affront".

HHLA said its management board would review the offer from MSC, which is privately owned by the Aponte family.

HHLA earlier this year sold a stake in one of its three terminals in Hamburg port to Chinese shipping firm Cosco, in a deal that was met with protests within Germany's government coalition and from abroad over concerns about increasing Chinese influence.

German ports are facing major challenges amid weak foreign demand and fierce competition with Belgian and Dutch counterparts.

($1 = 0.9312 euros)

(Writing by Friederike Heine and Maria Sheahan; Editing by Jason Neely, Mark Potter and Emelia Sithole-Matarise)