Ethiopia's military leader sharply attacked President Carter yesterday, accusing him of coordinating a plot to have Middle Eastern nations come to the aid of Somalia with weapons and, if necessary, troops.

The personal criticism of Carter by Lt. Col. Mengistu Haile Mariam appeared to be the sharpest yet in Ethiopia's escalating war of words with the United States over its diplomatic role in the conflict between Ethiopia and Somalia. Somali forces occupy most of Ethiopia's Ogaden region.

In recent days Ethiopia has summoned home its ambassador to Washington for consultations and threatened to break relations with the United States. Somalia has charged that Ethiopia, backed by Cuban and Soviet forces, plans to invade Somalia and has criticized the United States for denying it military aid in the face of a massive Soviet buildup of the Ethiopian military.

The United States has warned the Soviets against intervention in the region, calling for the big powers to leave the solution to the countries themselves, the United Nations and the Organization of African Unity.

Ethiopian leader Mengistu, in a nationwide broadcast over Addis Ababa Radio, said Carter, during his recent trip to Europe and the Middle East, had sought "to coordinate a plan" to assist Somalia which involved the United States, Iran, Saudi Arabia, Egypt, Kuwait and West Germany.

"The president has tried to present Ethiopia, the country which has been invaded, as the invader - and Somalia, the invading country, as the peace-seeker," Mengistu said.

He said the agreement, allegedly worked out by Carter during his trip, called for Iran, Saudi Arabia, Kuwait and West Germany to provide funds for Somalia to buy weapons in Western Europe and the United States. He added that Egypt would give Somalia arms from its stockpile of Soviet weapons.

"If, with all this arms assistance, Somalia is still unable to extend its invasion, Iranian forces will directly intervene and fight alongside Somali forces," with Saudi air support, Mengistu said.

In another development, diplomatic sources in Mogadishu said that Ethiopian warplanes, piloted by Cubans, had driven Somali forces from the strategic Ogaden city of Harrar. The sources, quoted by United Press International, said that the Somali forces, which reportedly controlled most of Harrar last week, pulled back about two miles last weekend after dawn-to-midnight bombardment.