GIFU, Japan — Liu Hongmei was fed up with her job at a Shanghai clothing factory, where she worked long hours for little pay.

So three years ago, she quit to take a job in Japan. A garment factory there promised Ms. Liu three times her $430-per-month Chinese wage, and she hoped to save thousands of dollars for her family, which was growing with the recent birth of a son.

“It seemed like a big opportunity,” she recalled.

Call it an opportunity, maybe, but don’t call it work. Legally, the time Ms. Liu spent ironing and packing women’s wear in Japan is considered “training.” She had entered the murky and at times abusive world of Japan’s technical trainees — essentially second-class laborers brought in from abroad to fill jobs that Japanese citizens aren’t taking.

Just like the United States and other developed countries, Japan has a hard time finding people to pick vegetables, collect nursing-home bedpans and wash restaurant dishes. In America, many of these low-skilled, low-paying jobs are filled by illegal immigrants, an arrangement attacked by President Trump during his campaign.

Japan, on the other hand, long ago achieved what Mr. Trump has promised: It has very little illegal immigration and is officially closed to people seeking blue-collar work.

Now, though, its tough stance on immigration — legal and illegal — is causing problems. Many Japanese industries are suffering from severe labor shortages, which has helped put a brake on economic growth.

That is prompting Japan to question some fundamental assumptions about its labor needs. The debate is politically delicate, but changing realities on the ground — in Japan’s factories and fields — are forcing politicians to catch up. Japan’s total foreign-born labor force topped one million for the first time last year, according to the government, lifted in part by people entering the country on visas reserved for technical trainees.

That growth has also led to an increase in cases of worker abuse and fraud, labor activists say.

Ms. Liu is part of that debate. She arrived in Japan in debt after paying brokers $7,000 to arrange her visa. Once there, she said, she found onerous working conditions and lower-than-promised pay.

Her bosses, she said, “treat us like slaves.”

Technically ‘Training’

Ms. Liu and other Chinese workers at her factory came to Japan through a government-sponsored internship program. Its purpose is to square the circle between Japan’s labor shortage and its ban on low-wage immigration.

Farms, food-processing businesses and many manufacturers would struggle to stay afloat without foreign trainees, specialists say.

“Practically every vegetable in the supermarkets of Tokyo was picked by a trainee,” said Kiyoto Tanno, a professor at Tokyo Metropolitan University.

To appease business groups, the government has created immigration loopholes, and hundreds of thousands of low-wage workers like Ms. Liu have poured through them. They come from China and Vietnam, the Philippines and Cambodia, and they are filling empty jobs in Japan as the Japanese population shrinks, becoming a crucial if underacknowledged motor of the economy.

Their numbers are soaring. The trainee program has doubled in size in the last five years, to over 200,000, according to official data, and the government is planning to expand it. The biggest source of workers has been China, but much of the recent growth has come from Vietnam.

Few doubt that “training” is a fig leaf. Beyond a short period of language study, most trainees receive little or no instruction that would distinguish them from regular manual laborers, specialists and participants say.

“The system is like calling a crow white,” said Yoshio Kimura, a member of Parliament from the governing Liberal Democratic Party who heads the party’s labor committee. “What we’re really doing is importing labor.”

Training is not the only way around Japanese immigration restrictions. There are also students in part-time jobs, asylum seekers waiting for refugee applications to be processed — almost all are ultimately rejected — and South Americans of Japanese descent who can obtain special visas based on their ancestry.

Demand still outstrips supply. The number of working-age Japanese has been falling since the mid-1990s, a consequence of decades of low birthrates. Nationwide unemployment is just 3 percent, and in some places, jobs are simply going begging. There are three to four positions open in nursing care and construction for every person who applies, according to government surveys.

Eventually, Japan plans to lengthen the maximum time that trainees can stay in the country to five years, from three, and allow more kinds of businesses to hire them, including nursing homes and cleaning companies for offices and hotels.

Parliament approved the creation of a new agency to oversee the trainee program last year, in response to criticism over worker exploitation. Once it is in place, the plan is to bring in more workers.

Mr. Kimura and some other lawmakers want to go further, by establishing a formal guest worker system. Though it would not open a path to immigration — workers would still be expected to go home eventually — it would be more forthright than the current approach.

Business groups favor the proposal, and the Liberal Democrats approved it as party policy in May. The government of Prime Minister Shinzo Abe has not indicated whether it will follow through.

“If we want economic growth in the future, we need foreigners,” Mr. Kimura said.

Can’t Walk, Can’t Leave

Nobuya Takai, a lawyer who has represented foreign trainees in labor disputes, said the pretense that trainees are not workers contributes to problems.

Companies do not hire them directly, but through a byzantine system of government and private-sector middlemen. Most trainees end up thousands of dollars in debt to pay broker fees before they even arrive, say Mr. Takai and others who have studied the program. And because trainees cannot easily switch jobs — their visas tie them to a single company — they lack what should be major leverage: the ability to walk out on a bad employer.

“They can’t change jobs, and they lose money if they go home,” Mr. Takai said.

In 2011, an American State Department report on human trafficking flagged the trainee program for what it said were inadequate protections against “debt bondage” and other abuses. When trainees don’t save enough to repay broker fees, they sometimes stay on illegally. Almost 6,000 did so in 2015, according to Japan’s Justice Ministry. (There are about 60,000 foreigners total in Japan without valid visas, according to the government, compared with an estimated 11 million unauthorized immigrants in the United States.)

The New York Times spoke with more than a dozen trainees. All of them said they had paid labor brokers in their home countries, usually $7,000 to $11,000, to come to Japan to work. Most borrowed the money from family or banks.

The trainees came from several countries in Asia and worked in different industries, in different parts of Japan: a Cambodian construction worker, a Chinese lettuce picker, seamstresses from China and Vietnam.

Complaints about unpaid labor were common. Cao Bao, a 33-year-old from Jilin Province in northeast China, worked for Kishimoto Manufacturing, a small auto parts supplier in central Japan.

He said Chinese trainees there were made to clean and paint the factory on their days off, without pay, when managers found errors in their work. He was fired when he complained, he said, and a Japanese labor union has taken up his case.

“Some Japanese are helpful and nice, but the people at the company are different,” Mr. Cao said.

Masahisa Kishimoto, the company’s president, said Mr. Cao had left of his own accord, and he blamed cultural differences for problems at the factory. In China, he said, “they don’t clean.”

“There are no rules,” he continued. “There’s a sense that you if you don’t get caught, you can do anything.”

Mr. Kishimoto referred other questions to Joho Highway Co-op, an employers’ association that recruits trainees on behalf of Kishimoto Manufacturing and other local businesses. The co-op said that Kishimoto had been imposing “penalty” overtime on both Japanese and Chinese workers, in violation of labor rules, and that Kishimoto had compensated the employees after the co-op intervened. Mr. Kishimoto said the company had fully complied with labor laws.

Government data on workplace accidents shows that trainees are more likely to be hurt on the job than Japanese workers — a result of poor training, language barriers or more dangerous assignments. Since 2010, two trainee deaths have been recognized by the government as cases of karoshi, the Japanese term for death by overwork. Given widespread underreporting of overtime, the true number could be higher.

In the financially struggling garment industry, abuses are pervasive enough that the minister of economy, trade and industry promised an inquiry last year, during a debate in Parliament over expanding the trainee program.

Tham Thi Nhung, 32, a mother of two from Vietnam, said she worked from 8 a.m. to 9 or 10 p.m. Her job was to sew jackets, coats and dresses at a small clothing factory in Aichi prefecture, an industrial region in central Japan.

All but one of the business’s six seamstresses were Vietnamese, Ms. Nhung said. They hadn’t had a day off in four months, she said, but the owner was recording only part of their overtime. In November, after the women complained that they were being underpaid by $712 a month, the owner sent a letter saying the factory was closing, and they were being laid off.

A telephone number registered for Ms. Nhung’s employer, Fashion Ai, was not working, and a lawyer representing the company declined to comment.

“We told the boss, but she said she wouldn’t pay more,” Ms. Nhung said. “She told us to keep working or go back to Vietnam.”

Unpaid Debts

Ms. Liu said she emptied her savings and borrowed from relatives to cover the visa fee.

Ms. Liu and her colleagues said their employer had been paying them less than the legal minimum wage for overtime, and had been overcharging them for company housing.

The employer was 50-year-old Takeshi Nakahara, who along with his wife owns several small garment factories in Gifu, near Aichi. He started using Chinese trainees 15 years ago, he said in an interview, because “no Japanese want to work in the apparel industry.”

Low wages are the only way to compete with cheap foreign factories, he added. “Most manufacturers have moved overseas,” he said. “It’s the only way to stay profitable.”

Mr. Nakahara said he had been paying Ms. Liu and other Chinese workers less than minimum wage for overtime, though he said the idea had been theirs. “They demanded more overtime work,” he said. “I told them it wouldn’t be profitable for the company, and they said they were willing to work for less.”

Although the arrangement was illegal, he said he felt betrayed when the women, nearing the end of their three-year contracts, made demands for pack pay.

The workers sought help from Zhen Kai, a Chinese labor activist who has lived in Japan for decades. He operates a small union office in Gifu that includes temporary rooms in which workers can stay.

Mr. Zhen says that he sympathizes with the businesses and that many would have folded without the trainee program. The government, he says, has effectively kept such businesses alive by letting them exploit workers.

“Owners often say to me, ‘Are you trying to destroy my company?’” he said.

Mr. Zhen negotiated with the Nakaharas, who offered a settlement, initially about $5,800.

Fed up and homesick, Ms. Liu accepted the offer and was getting ready to go back to China, even though she still owed money to the relatives who helped her pay for her visa. The other four women decided to stay in Japan to fight for more compensation, and a few weeks later accepted offers of $10,000 to $16,000.

Asked if they had learned anything during their ostensible training, they laughed bitterly. “Only hardship,” Ms. Liu said.

“My image of Japan,” she said, “was that it was a good country.”