The Norwegian-flagged Ocean Viking, run by charities MSF and SOS Mediterranee, had been seeking a port after rescuing four boats of migrants off the Libyan coast between August 9 and 12.
After talks with the European Commission, Malta agreed its navy would transfer the migrants to the island but not be allowed to stay.
They will be relocated to other member states, Maltese Prime Minister Joseph Muscat tweeted, listing destination countries as France, Germany, Ireland, Luxembourg, Portugal and Romania.
Charities had warned that food supplies on the 69-metre (220-foot) boat were running out and staff were jubilant as the deal was announced.
"Good news!" rescue operator Nicholas Romaniuk told AFP, while saying they did not know when the migrants would be transferred.
The agreement was made as another rescue boat, the Mare Jonio, set off for Libyan waters, the Italian left-wing collective Mediterranea which runs the ship said in a tweet.
Food running out
Rescue charities have been scathing of the lack of coordination and solidarity among EU member states in dealing with migration standoffs over the past years, with tens of thousands of people making the perilous trip across the Mediterranean.
"We are relieved this long ordeal for the 356 people we have on board is finally over. Was it necessary to impose two weeks of excruciating wait for rescued people to be disembarked?" said Jay Berger, MSF's project coordinator onboard the Ocean Viking.
"This 14-day standoff of the Viking Ocean was shocking," Frederic Penard, director of operations at SOS Mediterranee, said in a statement.
"We hope that the ad hoc solution implemented today will transform into the predictable and sustainable disembarkation mechanism promised many times by several European Union member states," he said.
The charity said the Ocean Viking would now change crews, refuel and be resupplied before heading back to Libyan waters.
The boat had been denied entry to dock by both Malta and Italy and is just the latest in a string of migrant ship standoffs.
Italy's far-right Interior Minister Matteo Salvini has repeatedly insisted that rescued migrants can only land in Italy if other EU countries take them in.
He has been accused of demonising migrants and leaving them to drown in the sea.
As a political crisis plays out in Rome following the break up of the coalition government, Salvini tweeted that he had been vindicated.
"As promised, we did not give the 356 migrants on the Ocean Viking permission to disembark in Italy. The safety of Italians comes first!" he wrote.
Most of the migrants on the Ocean Viking are adult men.
About two-thirds come from Sudan, with others from Ivory Coast, Mali and Senegal.
Four women and five young children, aged one to six, are also aboard.
Almost a hundred are under the age of 18.
The French government said it would take in 150 of those aboard.
Many were rescued from Libyan waters suffering from severe dehydration and sometimes borderline malnutrition, the boat's medical team has said.
They tell stories of fleeing conflict-torn Libya to escape ill treatment, arbitrary detention and sometimes torture.
MSF tries to ensure those rescued eat at least one hot dish a day, as well as providing cereal bars, protein biscuits and tea.
With limited water, those aboard are restricted to three-minute showers twice per week.