EDITOR'S NOTE: This is last in a series of stories on the loss of middle-class jobs in the wake of the Great Recession, and the role of technology.

WASHINGTON — They seem right out of a Hollywood fantasy, and they are: Cars that drive themselves have appeared in movies like “I, Robot” and the television show “Knight Rider.”

Now, three years after Google invented one, automated cars could be on their way to a freeway near you. In the U.S., California and other states are rewriting the rules of the road to make way for driverless cars. Just one problem: What happens to the millions of people who make a living driving cars and trucks — jobs that always have seemed sheltered from the onslaught of technology?

“All those jobs are going to disappear in the next 25 years,” says Moshe Vardi, a computer scientist at Rice University in Houston. “Driving by people will look quaint; it will look like a horse and buggy.”

If automation can unseat bus drivers, urban deliverymen, long-haul truckers, even cabbies, is any job safe?

Vardi poses an equally scary question: “Are we prepared for an economy in which 50 percent of people aren't working?”

An Associated Press analysis of employment data from 20 countries found that millions of mid-skill, mid-pay jobs already have disappeared over the past five years.

What lies ahead?

That experience has left a growing number of technologists and economists wondering what lies ahead. Will middle-class jobs return when the global economy recovers, or are they lost forever because of the advance of technology? The answer may not be known for years, perhaps decades.

To understand their arguments, it helps to understand the past.

Every time a transformative invention took hold over the past two centuries, businesses would disappear and workers would lose jobs. But new businesses would emerge that employed even more.

The combustion engine decimated makers of horse-drawn carriages, saddles, buggy whips and other occupations that depended on the horse trade. But it also resulted in huge auto plants that employed hundreds of thousands of workers, who were paid enough to help create a prosperous middle class.

“What has always been true is that technology has destroyed jobs but also always created jobs,” says Nobel Prize-winning economist Joseph Stiglitz of Columbia University.

The astounding capabilities of computer technology are forcing some mainstream economists to rethink the conventional wisdom about the economic benefits of technology, however. For the first time, we are seeing machines that can think — or something close to it.

In the early 1980s, at the beginning of the personal computer age, economists thought computers would do what machines had done for two centuries — eliminate jobs that required brawn, not brains.

Low-level workers would be forced to seek training to qualify for jobs that required more skills. They'd become more productive and earn more money. The process would be the same as when mechanization replaced manual labor on the farm a century ago; workers moved to the city and got factory jobs that required higher skills but paid more.

But it hasn't quite worked out that way. It turns out that computers most easily target jobs that involve routines, whatever skill level they require. And the most vulnerable of these jobs, economists have found, tend to employ midskill workers, even those held by people with college degrees — the very jobs that support a middle-class, consumer economy.

A new threat

So the rise of computer technology poses a threat that previous generations of machines didn't: The old machines replaced human brawn but created jobs that required human brains. The new machines threaten both.

“Technological change is more encompassing and moving faster and making it harder and harder to find things that people have a comparative advantage in” versus machines, says David Autor, an economist at the Massachusetts Institute of Technology who has studied the loss of midpay jobs to technology.

Here are a few scenarios that economists and technologists offer about jobs in the future:

• Healthy economy

It has always happened before. Europe and the United States endured repeated economic and social upheaval during the 19th and early 20th centuries as their agricultural economies transformed into industrial ones. Columbia's Stiglitz argues that such pressures led to the collapse of the world economy in 1929 — the cataclysm we call the Great Depression.

The mechanization of farming caused agricultural production to soar worldwide in the 1920s — and prices to plunge. American farmers, who accounted for a fifth of the U.S. workforce, lost purchasing power and also struggled to pay their mortgages and other loans.