Tom Gjelten is a correspondent for NPR News and the author of “A Nation of Nations: A Great American Immigration Story.”

Fifty years ago this week, after taking a curious route to the president’s desk, one of the most underestimated bills in U.S. history was signed into law. The 1965 Immigration and Nationality Act (INA) would end up changing the face of the United States as much as any measure enacted in the 20th century. But that was largely because of a miscalculation by a congressman who thought he was limiting the bill’s effect.

The law ultimately ended the use of national-origin quotas, under which immigrants were chosen on the basis of their race and ancestry, with Northern and Western Europeans heavily favored over all other candidates. During the congressional debate over the proposed reforms, supporters of the old national-origin approach countered that the United States had always been a European country with an Anglo-Saxon heritage and that it should stay that way. Rep. Ovie Fisher (D-Tex.) complained that the new legislation “shifts the mainstream of immigration from western and northern Europe — the principal source of our present population — to Africa, Asia, and the Orient.”

The bill’s main sponsors were two liberal Democrats, Sen. Philip Hart of Michigan and Rep. Emanuel Celler of New York. Celler had been a member of Congress since 1923, the year before the national-origin quotas were enacted, and he had spent his entire congressional career working for their elimination. Hart was a leader in the fight for the 1965 Voting Rights Act, and he said the INA was justified by the same concern for equal justice. Edward Kennedy (D-Mass.) served as the floor manager for the bill in the Senate.

Organized opposition to the legislation was led by a motley assortment of conservative groups with nativist tendencies. They had an ally in the chairman of the House immigration subcommittee, Ohio Rep. Michael Feighan, a conservative Democrat who initially refused even to schedule hearings on the proposed reforms.

After coming under heavy pressure from President Lyndon B. Johnson, Feighan relented, but he extracted a key concession. The original Hart-Celler bill gave visa preference to foreigners whose skills and training were deemed “especially advantageous” to the United States, without special regard for their national origin. “A nation that was built by immigrants of all lands,” Johnson said in his 1964 State of the Union address, “can ask those who now seek admission: ‘What can you do for our country?’ But we should not be asking: ‘In what country were you born?’ ” As his price for supporting the bill, Feighan insisted that the emphasis on immigrant employability be downgraded, with the top visa preference given instead to those seeking family unification. The single largest visa category was reserved for brothers and sisters of U.S. citizens, a category barely considered in the original Hart-Celler formula.

Supporters of the national-origin quotas believed they served to maintain the existing racial and ethnic composition of the U.S. population and keep out undesirable nationalities. Feighan figured the same result could be achieved by making family unification the top immigration goal. He convinced his conservative allies that a family-unification preference would amount to “a naturally operating national-origins system,” in the words of an American Legion commentary. “Nobody is quite so apt to be of the same national origins of our present citizens as are the members of their immediate families,” opined two Legion representatives.

The reasoning was so compelling that some critics of the national-origin quotas feared they had been outmaneuvered. The Johnson administration and other backers of the Hart-Celler legislation, focusing narrowly on the elimination of the discriminatory quota system, went along with Feighan’s changes. The INA, as amended by Feighan, was signed into law by Johnson on Oct. 3, 1965, in an elaborate ceremony on Liberty Island in New York.

Neither the liberals nor the conservatives fully understood what they had done. The elevation of the family unification preference ultimately facilitated a process of chain migration. An engineer from India with a U.S. job offer or a Korean woman married to a member of the U.S. military, once naturalized as U.S. citizens, could sponsor the immigration of all their brothers and sisters plus their spouses, who in time could arrange for the immigration of their own siblings.

The migration dynamic was reinforced by changes in the international order. In Europe, economic and social pressures were no longer pushing people to seek new opportunities abroad. At the same time, the developing countries were experiencing population growth, rising aspirations and heightened conflict, so more people in those regions wanted to move. In the 50 years after 1965, the percentage of the U.S. population born outside the country tripled and shifted dramatically in complexion. In 1960, seven of eight immigrants were white people from Europe. By 2010, nine out of 10 newcomers were immigrants of color from outside Europe, and the vast majority were coming under the family-unification provisions of U.S. immigration law. Feighan’s scheme to create a “naturally operating national origins system” had backfired.

The story of the 1965 immigration act shows that a law can have monumental consequences that neither its backers nor its detractors anticipate. Almost no one realized the legislation would result in a demographic transformation of the United States, with a new population of unprecedented diversity.

Unintended, however, does not mean unfortunate. Politicians debate what should be done about people who come to the United States outside the law, but the immigrants who arrived as a result of the 1965 act waited their turn, contributed to the U.S. economy and enriched the nation’s culture. We have long claimed to be an exceptional country of opportunity, but it took a mostly unintentional opening to the world to finally put that promise to the test.