The migrants, many of whom have been stranded for over a month, had been driven to the desert area of Ras Jedir by Tunisian authorities and left there to fend for themselves, according to witnesses, rights groups and United Nations agencies.
Aid groups said three groups of about 300 migrants from sub-Saharan African countries in total remain stranded there in life-threatening conditions.
A spokesman for Tunisia's interior ministry, Faker Bouzghaya, said during a joint meeting with Libyan authorities in Tunis that "we have agreed to share the groups of migrants who are at the border."
"Tunisia will take charge of a group of 76 men, 42 women and eight children," Bouzghaya told AFP.
He said the groups were transferred on Wednesday to reception centers in the cities of Tatouine and Medenine and provided with health and psychological care, with the help of the Tunisian Red Crescent.
Under the agreement, Libya will take in the remaining 150-200 migrants, humanitarian sources said.
The Libyan interior ministry earlier on Thursday announced the bilateral agreement to "put an end to the crisis of irregular migrants stranded in the border area."
In a later statement, it said there were no more migrants stranded at the border following the agreement, adding that joint patrols were being organized to "secure the border."
Migrant deaths
Racial tensions had flared in Tunisia's second city of Sfax after the July 3 killing of a Tunisian man following an altercation with migrants.
Up to 1,200 Black Africans were "expelled, or forcibly transferred by Tunisian security forces" to desert border regions with Libya and Algeria, Human Rights Watch said.
The Tunisian Red Crescent had on July 12 provided shelter to about 630 migrants found at Ras Jedir, as well as 200 others who had been pushed towards Algeria, non-governmental groups said.
But AFP journalists and other media had reported that about 350 migrants had remained stranded at Ras Jedir in the following weeks.
Some 40 kilometers (25 miles) south at Al-Assah, hundreds of other migrants were seen pouring into Libya, with no access to food, water and vital supplies until they were rescued by Libyan border guards in early August, according to an AFP team there.
Since the start of July, "at least 27 migrants" were found dead after being abandoned in the Tunisian-Libyan border area and another 73 were missing, a humanitarian source told AFP on Thursday.
Until Wednesday, migrants had continued to arrive in Libya at Al-Assah at a rate of about 50 per day before being rescued by Libyan guards, the same source said.
Libyan authorities have come under sharp criticism by the U.N. over reported violence against migrants, about 600,000 of whom reside in the war-scarred North African country.
The two North African countries are major gateways for migrants and asylum seekers attempting perilous voyages in often rickety boats in the hopes of a better life in Europe.
Mediterranean Sea crossing attempts from Tunisia had multiplied in March and April following a incendiary speech by President Kais Saied who had alleged that "hordes" of irregular migrants were causing crime and posing a demographic threat to the mainly Arab country.
Xenophobic attacks targeting Black African migrants and students have increased across the country since Saied's February remarks, and many migrants have lost jobs and housing.
At least 11 migrants died in a shipwreck off the coast of Sfax, local court spokesman Faouzi Masmoudi said on Monday, adding that another 44 were missing and only two were rescued.
The distance between Sfax and Italy's Lampedusa island is only about 130 kilometers (80 miles).
The U.N. has described the central Mediterranean migration route as the world's deadliest, claiming hundreds of lives each year