MORE THAN 1,200 Massachusetts companies hired 5,481 skilled foreign workers last year through a controversial visa program that is simultaneously being praised for helping to plug holes in the state’s tech workforce and criticized as a way to replace US employees with cheaper foreign labor.

The H-1B visa program, which allows skilled foreign workers to be brought into the country for stays of up to three years, is used by Massachusetts companies engaged in high tech, life sciences, and the law, as well as hospitals, colleges, banks, construction firms, and even the public school systems of Cambridge and Newton. Massachusetts currently ranks sixth in the nation in terms of H-1B workers, behind California, New Jersey, Texas, New York, and Florida, according to data supplied by the US Citizenship and Immigration Services.

While many companies participate in the program, the bulk of visas flow to a small group. In 2012, nearly 41 percent of the visas issued to Massachusetts companies were handed out to just 10 companies. The group included such well-known firms as EMC Corp., Harvard University, MathWorks, Partners Healthcare, Fidelity Investments, Children’s Hospital, and the Boston Consulting Group.

Few of the companies would discuss their H-1B programs, but those that did comment said they only seek out foreign workers who have skills that cannot be found in Massachusetts. Kevin Galvin, a spokesman for Harvard, says the university seeks H-1B visas for highly skilled faculty and researchers working in the fields of chemistry, engineering, physics, the biological sciences, and medicine. “As a general practice, the university does not sponsor administrative or support positions with H-1B visas, and it does not provide visa sponsorship for positions that could be filled by US workers,” he says.

The Massachusetts company that received the most H-1B visas in fiscal 2012 was Patni Americas Inc. of Cambridge, which has since been acquired by iGATE Corp. of Fremont, California. Both companies cater to firms that want to outsource jobs. Patni, according to those familiar with its work, brings foreign workers into the United States on visas and then contracts them out to do information technology work for American firms.

Patni applied for 1,779 H-1B visas in 2012 and received 1,260, or 23 percent of the total issued to companies in Massachusetts. Officials at Patni and iGATE, which has extensive operations in India, did not respond to requests for interviews.

iGATE made headlines in Canada in April when press reports indicated 45 IT employees at the Royal Bank of Canada were being replaced by temporary foreign workers brought into the country by the firm. Canadian officials are investigating whether the outsourcing broke federal rules.

Ronil Hira, an associate professor of public policy at the Rochester Institute of Technology and the author of Outsourcing America, says more than half of the H-1B visas issued nationally in 2012 went to outsourcing firms such as Patni. Hira says the firms pay their H-1B workers less than American workers and use the savings to secure work from American firms looking to outsource functions at lower cost. “They’re essentially reselling labor,” Hira says.

Neeraj Gupta, who worked in two top positions at Patni until 2009, says many American companies use H-1B visas to recruit top-flight engineers from around the world to work for them. But he says other firms have discovered that H-1B visas allow them to cut costs by hiring cheap foreign labor.

“It really is a form of outsourcing,” says Gupta, who now heads a company called Systems in Motion, which trains US workers to do tech work for companies. “We’re able to deliver high quality, high value locally. We’re finding a lot of success with the US workforce.”

At press time, legislation was just beginning to make its way through Congress to revamp the nation’s immigration laws. Most of the focus in Washington has been on what to do with the 11 million undocumented workers in the country illegally, but a provision in the legislation would revamp the H-1B visa program, upping the number of new visas issued each year from 65,000 to 110,000 and adopting reforms designed to curb abuse. The reforms include wage increases for H-1B workers, prohibitions on the displacement of US workers, and new H-1B application fees that would be used to fund training in math and science fields.

Sen. Orrin Hatch, a Utah Republican, says expanding the H-1B program is both good for business and the economy.

“For too long, our country just hasn’t been able to meet the demands for workers in the STEM fields,” Hatch said in a statement, referring to the shorthand for science, technology, engineering, and math. “Increasing the availability of workers who can fill these here in the US is good for workers, good for businesses trying to grow, and good for our economy. It just makes sense.”

Scott Corley, executive director of Compete America, an umbrella group supporting an increase in H-1B visas, says skilled foreign workers are badly needed to keep the US economy growing because American schools are not pumping out math and science graduates fast enough to keep pace with employment growth. He says 200,000 science and technology jobs could go unfilled by 2018.

Gupta says expanding the number of H-1B visas is un¬likely to help companies struggling to fill tech jobs. Gupta says the outsourcing companies have access to large groups of tech-oriented employees in India and other countries where they have business operations. He said the companies currently flood the US government with H-1B visa applications (the application process was cut off after five days this year) and will just ramp up their efforts if the pool of visas is expanded.

Hira says the H-1B program is deeply flawed because it allows employers to legally hire foreign workers at substantially lower wages than American workers and without giving American workers a first shot at the jobs. In testimony before the Senate Judiciary Committee in April, Hira said the program gives US employers enormous leverage because the sponsoring firm, not the foreign worker, holds the H-1B visa and if the worker is laid off he or she has to leave the country. “An H-1B worker is essentially indentured to a particular employer,” Hira testified.

In an interview, Hira says companies often claim they use the H-1B program to bring in skilled workers they can’t find in the United States. If that were the case, he says, you would expect the employers to seek green card permanent status for their worker so they wouldn’t be lost when their visa expires. Yet Hira’s research indicates very few of the outsourcing companies seek green cards for their H-1B workers. Patni, for example, sought green cards for only 2 percent of their H-1B visa holders in 2012, Hira says, while Microsoft sought permanent status for all of its H-1B workers.