Ideological extremism comes from the naive and rigid belief/conviction that one model of society/government/economic system is not only the best, but the only correct, moral, acceptable one for a country and/or for all countries for all time to come.
One way this can be curbed, if not eliminated is if people are given a broad and enlightened education in history and schools of philosophical thought from an early age, and exposed to the positive aspects of opposing models.
Religious extremism arises from the naive and fanatical belief/conviction that only one religion and a particular sectarian version of it is the only road to God, and furthermore that it must be followed by or thrust upon every human being in the world.
The only way this type of extremism can be curbed, tamed, and controlled is:
(i) If and whenenlightened leaders with charisma emerge from WITHIN the religion who preach tolerance, common sense, and moderation in religious commitment, and are bold enough to declare the dangers and untenability of religious extremism in the modern world ;
(ii) and/or if millions of people from WITHIN the religion who have been enlightened, enraged, and instigated by powerful authors/thinkers from WITHIN the religion. rise up en masse against the stifling and disastrous extremism in which the so-called religious leaders have been brainwashing the people for centuries. This can only happen if/when the people at large realize that their minds have been held in slavery by orthodoxy and traditionalist theocratic preachers for centuries.