Ethiopian Prime Minister Abiy Ahmed's stated ambition to secure access to the Red Sea is a source of tension between the Horn of Africa nation and its neighbours and has raised concerns of a fresh conflict in the region.
Somalia, which considers Somaliland part of its territory, rejected the New Year's Day deal that would allow landlocked Ethiopia to lease 20 km (12 miles) around the port of Berbera, on the Gulf of Aden with access to the Red Sea, for 50 years for its navy and commercial purposes.
Ethiopia would in return become the first country to recognise Somaliland as an independent nation.
"This evening, I signed the law nullifying the illegal MoU between the government of Ethiopia and Somaliland," Mohamud posted on X, formerly Twitter, late on Saturday.
"This law is an illustration of our commitment to safeguard our unity, sovereignty and territorial integrity as per international law."
The Somali president did not specify what the new law says or when parliament passed it.
There was no immediate comment from Somaliland or Ethiopian officials.
Abiy said in October that Ethiopia's existence was "tied to the Red Sea", adding that if countries in the Horn of Africa "plan to live together in peace, we have to find a way to mutually share with each other in a balanced manner".
His national security adviser has said Ethiopia would offer Somaliland an unspecified stake in state-owned Ethiopian Airlines in return for giving it access to the Red Sea.