The remarks by President Abdel Fattah al-Sisi were the strongest yet made on the issue by Egypt, which already has frosty relations with Ethiopia, and were a sign that Cairo may get involved in a dispute that has raised fresh tensions in the volatile Horn of Africa.
Somaliland declared independence from Somalia in 1991 but has not won recognition from any country. The port lease deal, which was agreed earlier this month but not yet finalized, would be a boon to landlocked Ethiopia and has enraged Somalia.
"Egypt will not allow anyone to threaten Somalia or affect its security," Sisi said, speaking at a news conference with visiting Somali President Hassan Sheikh Mohamud.
"Do not try Egypt, or try to threaten its brothers especially if they ask it to intervene," he added.
In a January 1 memorandum of understanding, Ethiopia said it would consider recognizing Somaliland's independence in return for the port access. It would lease 20 km (12 miles) of coastland around the port of Berbera, on the Gulf of Aden, for 50 years for military and commercial purposes.
Ethiopia's current main port for maritime exports is in the neighboring country of Djibouti.
"My message to Ethiopia is that ... trying to seize a piece of land to control it is something no one will agree to," Sisi said, saying cooperation on development was a better strategy.
Representatives for Ethiopia did not immediately respond to requests for comment on his statements.
Egypt's foreign minister last week called Ethiopia a source of instability in the region, which the country's foreign ministry said was "irrelevant."
Relations between Egypt and Ethiopia, which share use of the Nile River, have been tense for years over a major dam Ethiopia has built on the Blue Nile.
Forum