The two aid boats were about 5 nautical miles off the coast of Malta, which let them shelter in its territorial waters during the negotiations.
Germany expects to take in 60 migrants who were already in Malta or are about to arrive there under an agreement to defuse the latest standoff over rescue ships in the Mediterranean Sea.
The deal, announced by Maltese Prime Minister Joseph Muscat, breaks a stalemate that began after 32 were rescued by a German aid group's vessel on December 22.
The Dutch-flagged vessel sea-watch 3, which is operated by a German humanitarian organization, rescued 32 migrants including women, children and unaccompanied minors off the coast of Libya in late December.
The deal also meets Malta's demand for other countries to take numerous 249 migrants Maltese military vessels rescued in late December.
EU Migration Commissioner Dimitris Avramopoulos said Wednesday that "the past weeks have not been Europe's finest hour".
The 49 rescued migrants who were stranded at sea since last month will be brought to Malta and then distributed among eight European Union countries.
"After 19 days at sea, our guests finally have a safe haven", Sea-Watch tweeted.
According to the Telegraph, of the total, 176 would be sent to Germany, France, Portugal, Ireland, Romania, Luxembourg, the Netherlands and Italy. "This represents a confession of state failure, policy must not be made at the expense of people in distress".
But EU members have failed to agree on a permanent mechanism to relocate migrants who reach Europe's shores, even though arrivals have dropped sharply since a peak more than three years ago.
Malta has announced that it will allow two ships, stranded for weeks with 49 migrants and refugees on board, to dock.
The exact number of migrants that Italy has agreed to host has not been announced, but Conte had previously indicated that Rome was willing to welcome around 15.
Spanish police say they have broken up a gang that smuggled people and drugs by boat from Morocco into Spain, charging migrants up to 2,000 euros ($2,300) a trip.