Global trade and investment have been great engines of progress for much of the world. Over the past two decades, poorer countries reduced the gap between themselves and their richer counterparts for the first time since the Industrial Revolution, in no small part because of the opportunities opened by global trade. Technology has the same transformative potential in industries as varied as energy, health care, transportation, and education. New inventions that are imminent or already here could transform the lives of billions of people for the better.

Yet, as we see in the 2016 US election campaign, and as we have seen in Europe and elsewhere, rapid change has a dark side. If too many people are unable to adapt quickly and successfully to these changes, they will push back – blaming trade or immigrants or the elites – and demand a reversion to a simpler time.

The task of governments is to help people manage these transformations so that the changes benefit many and do as little harm as possible. In the United States, governments mostly failed at that task during the era of globalization. If the full benefits of the coming technologies are to be enjoyed, governments will have to do much better this time around.

The competitive pressures create by globalization should have been no surprise. About 45 years ago, President Richard Nixon’s top international economic adviser, Pete Peterson, warned him that rising competition from Japan and Germany, with much more on the way, “poses adjustment policy which simply cannot be ignored.”

Americans have unquestionably gained by the lower prices and higher quality that import competition enabled. Apple iPhones and the latest Boeing jets are the result of the collective input of tens of thousands of collaborators in dozens of countries around the world. But many Americans lost well-paid manufacturing jobs to import competition or outsourcing, and the US government has made little effort to mitigate those costs, even in worker retraining.

President John F. Kennedy promised in 1962 that the government would help American workers who lost out to trade competition as the United States lowered its barriers to imports. “When considerations of national policy make it desirable to avoid higher tariffs, those injured by the competition should not be required to bear the full brunt of the impact,” he said. But today, the United States spends a smaller proportion of its wealth on worker retraining than any of the other 34 member countries of the Organization for Economic Co-operation and Development except for Mexico and Chile.

Too often, the attitude of the US government has been deeply irresponsible, assuming that markets would simply sort everything out for the best. In the long run, everybody may end up with work and income, but in the short run, as Peterson told Nixon, the failure to help Americans adapt to the new reality will “leave long periods when the transition is painful beyond endurance.”

With technology change, too, we know well in advance exactly what is coming. Driverless technology, for example, will soon become the standard in the trucking industry. Driverless trucks can run 24 hours a day and won’t demand overtime pay. There are 3.5 million truck drivers in the United States, and an additional 5.5 million jobs in related industries – roughly one in every 15 American workers. They could perhaps go to work for UPS or deliver pizzas, but many of those delivery jobs will be lost to drones.

Personal-care robots will increasingly replace home health-care aides, and self-checkout machines are already replacing retail-store clerks; these are jobs that filled some of the gap left by the disappearance of manufacturing jobs to global competition, but they, too, will soon be under siege.  Automation is even hitting law and education, two sectors long thought immune to technological substitution.

These vulnerabilities necessitate something that too often was absent in the era of globalization: good public policies. Artificial intelligence will transform teaching, for example, but without access to the highest-speed broadband, students in poor and rural areas will fall further behind their urban counterparts. And unless we strengthen social safety nets and retraining schemes, there will be far too many losers in the labor market. There is no way to avoid the huge impact that technology will have on employment; we have to prepare for it and help those whose skills it antiquates.

Much more even than globalization, technology is going to create upheaval and destroy industries and jobs. This can be for the better, helping us create new and more interesting jobs or freeing up time for leisure and artistic pursuits. But unless we find ways to share the prosperity and help Americans adapt to the coming changes, many could be left worse off than they are. And, as we have seen this year, that is a recipe for an angry backlash and political upheaval.

Edward Alden is senior fellow at the Council on Foreign Relations and author of Failure to Adjust: How Americans Got Left Behind in the Global Economy. Follow @edwardalden.

Vivek Wadhwa is Distinguished Fellow at Carnegie Mellon University Engineering at Silicon Valley and a director of research at Center for Entrepreneurship and Research Commercialization at Duke. Follow @wadhwa.