CAIRO — Facing dire warnings from the military about the country’s growing chaos, Egyptian opposition leaders banded together for the first time on Wednesday and pressed President Mohamed Morsi to form a national unity government as a way to halt the violence that has led to dozens of deaths over the past week.

But even as secular-leaning and Islamist groups crossed an ideological divide to try to find a way to end the simmering violence, Mr. Morsi rejected the idea during a visit to Germany, where he said a new government would be formed only after parliamentary elections in April.

“In Egypt there is a stable government working day and night in the interest of all Egyptians,” Mr. Morsi said after meeting with Chancellor Angela Merkel in Berlin.

Still, the opposition’s gamble offered the first recent indication that the nation’s political leaders were searching for common ground and a way out of the chaos. Egypt’s largest secular-leaning opposition bloc, the National Salvation Front, joined a hard-line Islamist group, the Nour party, which had been allied with the president and his movement, the Muslim Brotherhood, in calling for a new government.