DEAUVILLE, France — Leaders of the Group of 8 wealthiest industrialized nations pledged on Friday to send billions of dollars in aid to Egypt and Tunisia, hoping to reduce the threat that economic stagnation could undermine the transition to democracy.

At a series of working sessions that lasted until the early morning hours Friday, representatives of the Group of 8 expressed concern that the democracy movement in the Arab world could be “hijacked” by Islamic radicals if the West did not help stabilize the economies of the two countries that touched off the Arab Spring, according to two European diplomats who were present during the discussions.

Comparing the uprisings that are sweeping the region to the fall of the Berlin Wall, which eventually paved the way for a historic shift to democracy in Central and Eastern Europe, the group said in a communiqué that its aim was “to ensure that instability does not undermine the process of political reform.”

How much aid the Western powers would ultimately provide, and how effective any aid would be during volatile political transitions in the two countries, remained uncertain. The group’s official communiqué promised $20 billion, which would be a major infusion of funds.