By the early 20th century, American neighborhoods were highly segregated along racial lines, contrary to promises embodied in the post-Civil War constitutional amendments ending slavery and establishing equal rights.

Segregation was so far advanced by 1930 that neighborhoods in the average U.S. metropolitan area could not have achieved a random distribution of African Americans and whites unless fully 65 percent of blacks relocated, according to studies of census data by modern demographers.

Twenty years later, after the Great Depression and World War II, and after millions of African Americans left the South for the North in search of economic opportunity — and safety from racist violence — segregation had worsened significantly.

In 1950, achieving a random racial distribution of inhabitants in the average metropolitan area would have required nearly three-quarters of African Americans to change residence. And that level of segregation persisted through 1970.

In short, the middle decades of the 20th century were an age of ghettoization. In “The Color of Law,” Richard Rothstein shows how and why this happened, and it wasn’t by accident. Blacks did not move into overcrowded slums as a matter of group preference. Nor was private racial discrimination by white developers, banks and homeowners’ associations exclusively to blame, though it was certainly a key factor.

Rather, the federal government used its expanding power to promote apartheid-like separation of whites and blacks in cities and towns across the country.

When the U.S. housing market collapsed in the Great Depression, Washington took control and attempted to revive it through New Deal agencies, such as the Federal Housing Administration (FHA) and Home Owners Loan Corporation.

The segregation that President Franklin D. Roosevelt’s administration inherited reflected preexisting institutions, of which restrictive racial covenants may have been the most important. They were still relatively new, however. FDR might well have used his unprecedented leverage over housing finance to undo them.

Instead, the New Deal did the opposite. The FHA promoted racial covenants and other instruments of segregation through underwriting standards discouraging home loans in areas “infiltrat[ed]” by “inharmonious racial or nationality groups.” The rationale was the government’s need to protect its investment, and those of white homeowners, against the threat African American neighbors would pose to property values.

When World War II began, the federal government constructed dwellings for workers who flocked to defense-related factories. This housing, too, was allocated by race. In some affected localities, there was no housing segregation, nor even any particular history of Jim Crow, until the feds created it.

Rothstein tells the story of Richmond, Calif., across the bay from San Francisco. From 1940 to 1945, nearly 14,000 African Americans flowed into what was then a small Pacific Coast shipbuilding city. The government housed them in poorer-quality, officially segregated buildings, setting aside better homes for whites. This “established segregated living patterns that persist to this day,” Rothstein writes.

“The Color of Law” thus adds a necessary corrective to established narratives about the impact of the New Deal and World War II on U.S. domestic institutions. Two decades of Democratic dominance in Washington were indeed a time “When Affirmative Action Was White,” as the title of historian Ira Katznelson’s 2005 book about the period suggests.

And, as Rothstein shows, the effects lingered for decades. Homeownership was a key path to wealth in postwar America, yet many blacks were excluded. Today, the median white household’s net worth is 16 times that of the median African American household.

In 1948, the Supreme Court rendered restrictive covenants unenforceable. The postwar FHA eventually abandoned “redlining,” though not before underwriting new whites-only suburbs for returning veterans, including Long Island’s iconic Levittown.

Not until 1968 would a different kind of Democratic administration, that of President Lyndon B. Johnson, bring about the Fair Housing Act to undo the damage done by its predecessors (and by the Republican Eisenhower administration, whose Interstate Highway System sometimes displaced minority communities and facilitated the growth of white suburbs).

By outlawing overt discrimination, the Fair Housing Act helped bring about change. As of 2010, randomizing racial residential patterns in major metropolitan areas would require 47 percent of African Americans to move. This is down substantially from previous levels and 17 points away from the 30 percent level indicative of “low” neighborhood segregation, according to University of Michigan demographer William H. Frey.

Neighborhood segregation also eased because of factors such as the migration of middle-class blacks to suburbs in the South, including subdivisions that did not even exist prior to the Fair Housing Act. Urban sprawl, in that sense, has aided desegregation.

As Frey shows in his 2014 book, “Diversity Explosion,” some of the least-segregated metropolitan areas in America now are places like Raleigh, N.C., and Las Vegas. Immigration from Asia and Latin America has meanwhile fostered the rise of what Brown University sociologist John Logan has called “global neighborhoods.”

A discussion of such data would have strengthened Rothstein’s otherwise excellent book. The figures quantify how grievously mid-20th-century policies harmed African Americans, and the country, but also how close we are — or were — to undoing the damage.

Black-white segregation is still shamefully persistent, especially in older Northern cities such as Chicago and New York. Presidential administrations of both parties never fully enforced the most aggressive remedies in the Fair Housing Act, which made local communities’ access to federal housing dollars contingent on their efforts to “affirmatively further” fair housing — the opposite of federal policy in the ’30s and ’40s.

In the waning days of President Barack Obama’s second term, his housing secretary produced a regulation requiring states and localities to assess patterns of segregation and make plans to address them, with their federal aid ultimately on the line.

President Donald Trump’s election casts that long-postponed rule back into limbo. New Housing Secretary Ben Carson, an ultraconservative African American neurosurgeon who grew up in segregated Detroit, denounced Obama’s approach in a 2015 op-ed column.