Dilma Rousseff, the Brazilian president, has accused the nation's doctors of "immense prejudice" towards their Cuban counterparts after the first medics to arrive from Havana were greeted with jeers.

The Cuban doctors have been invited to work in Brazil to support the fragile health system – one of the issues that prompted mass protests in June. Under the government's Mais Médicos (More Doctors) programme, 4,000 Cuban professionals will work in poor and remote areas of Brazil that are short of hospital staff.

After the first contingent of 400 arrived at the weekend they were booed by local doctors, who oppose what they describe as a stop-gap measure that fails to address the need for more investment in hospitals and better pay for doctors.

A video of the encounter in Ceará shows Brazilian doctors chanting "slave" at the Cubans. This appeared to be a reference to a payment system under which the Cuban government will receive more than a quarter of the doctors' £2,700 monthly salaries.

The Brazilian Medical Association has filed a lawsuit in the supreme court questioning the need for the programme. One medical group in Minas Gerais says its members will refused to help the foreign doctors if they have problems.

The federal medical council, which licenses doctors, has stated that the recruitment of doctors with locally invalid diplomas and poor language skills is illegal and endangers the lives of Brazilians.Government officials have depicted Brazilian doctors as a cossetted urban elite, reluctant to move away from high-paying private institutions in Rio de Janeiro, São Paulo and other big cities.

The health minister, Alexandre Padilha, expressed outrage at their treatment by their Brazilian counterparts: "This is very brutal; it incites prejudice and xenophobia," he said.The president strongly defended the Cuban doctors in a radio interview on Wednesday in which she stressed that the newcomers would only work in the Amazon and in remote places where domestic doctors were unwilling to practise. According to the president, there are 700 municipalities in Brazil without a single doctor.

Rousseff noted that fewer than 2% of the doctors in Brazil were foreign, compared with rates of 25% in the US and 36% in Canada. The Mais Médicos initiative aims to address the shortage by recruiting health professionals from Portugal, Argentina and elsewhere, but the president said that only the doctors from Havana had been criticised.

"We have seen instances of immense prejudice against the Cuban doctors," she said. "I can assure you we will do all we can within the law to bring doctors to places where there are no doctors."

Medical expertise is one of Cuba's main exports and has been used to cement ties between Havana and political allies overseas.

There are Cuban doctors in more than a dozen nations, including Venezuela – where they were paid for in oil under the late president Hugo Chavez – and Haiti, where they have been on the frontline of efforts to rein in its cholera epidemic.

In Brazil, the plan to recruit Cuban doctors has been controversial since it was proposed earlier this year. In July, the government said it was postponing the programme in the face of demonstrations by Brazilian doctors, who insist the country can meet its needs with homegrown medics.

Last week, however, the health minister announced the overseas recruitment would go ahead to meet a shortfall in hospital staff in remote areas.

Brazil's healthcare system is challenged by inequality and vast distances. According to the World Bank, the country has 1.8 doctors for every 1,000 people – well below the 3.2 ratio in neighbouring Argentina, and significantly below those of Mexico, the US and UK.

In the first stage of the programme, Mais Médicos recruited 1,589 doctors, a third of whom were from other nations, including Spain and Russia. But the government has said that almost 10 times this number are needed to fill the gaps in rural areas, particularly in the poor north and north-east of the country.

The shortfall will largely be filled by qualified foreigners, who will be given three-year contracts. The government is also investing in medical colleges and hopes to see a sharp increase in the number of graduates over the next eight years.

The Cuban doctors have had three weeks to prepare for the very different medical system and language.

Juan Delgado, one of the Cuban doctors who was subjected to the "slave" chants , told reporters for the newspaper Folha that it would take time for attitudes to change. "This is not right, we are not slaves," he said, adding: "The Brazilian doctors should do the same as we do: go to assist in the poorest places."