Meles Zenawi told parliament on Thursday that the Islamic courts, who control much of southern and central Somalia, are a "clear and present danger".
"We are not saying that we will declare war against Somalia. It is the jihadists in the UIC [Union of Islamic Courts] who have repeatedly declared war on Ethiopia," he said.
The Islamic courts responded by saying they were ready to defend themselves from "reckless and war-thirsty" Ethiopia.
To resist this clear and present danger, the policy of this government is first to try to solve the problem through negotiation and dialogue," Meles said. "So far, our attempts have not been successful."
"When any country faces that type of danger it has the full right to defend itself against this threat. To exercise this right we have been preparing for this kind of response, because it is our responsibility."
Ethiopian plans
He gave no details on what the plans might be, but Ethiopia has been accused of sending troops into Somalia and massing more on the border.
"If Ethiopia is ready for war, we are very ready for the defence of our country," Abdurahim Ali Muddey, Islamic courts spokesman, said.
"We are not a threat to Ethiopia, but the presence of its troops in our homeland is a serious security risk to Somalia as well as Ethiopia," he told AFP news agency.
The Islamic courts has said that its fighters carried out attacks on Ethiopian military targets around Baidoa, the seat of the largely powerless interim government, on Sunday and Wednesday.
US invitation
Ethiopian opposition politicians refused to accept a motion endorsing the prime minister's statements, saying it was tantamount to a declaration of war.
"This motion needs to be amended and negotiated with the parties' representatives in the parliament," Beyene Petros, an opposition MP, told AFP news agency.
Peace talks aimed at averting a war collapsed earlier this month with the Islamists demanding the withdrawal of Ethiopian troops as a pre-condition to meeting delegates from the interim government.