ROME — Italian authorities arrested the captain of a humanitarian rescue vessel with 40 migrants aboard after the boat on Saturday docked on a tiny Italian island in defiance of orders not to enter port.

Sea-Watch 3, led by Carola Rackete, was the first rescue boat to directly challenge Italy’s decision last year to close its ports to ships carrying migrants rescued in the Mediterranean.

The country’s move — part of its hard-line stance against irregular migration — has left Europe struggling to manage even the fairly limited flow of people wanting to reach the continent from North Africa. Time and again, boats that have rescued migrants have found themselves in limbo for days or weeks.

On June 12, Sea-Watch 3 rescued 53 migrants who had left Libya in a flimsy dinghy. Some were evacuated to Italy for emergency medical reasons, but 40 remained aboard the 165-foot ship.

Rackete was told to return the migrants to Libya, which is racked by factional warfare. But she said that laws of the sea required her to take them to a safe port — and that Tripoli did not qualify.

The last stage of the 17-day standoff between Italy and Sea-Watch 3 played out in dramatic fashion.

Italian Interior Minister Matteo Salvini accused the “pirate” captain of ramming the vessel into a government motorboat as she steered the ship to dock on the island of Lampedusa. Initial video from the port, however, did not clearly show any contact.

“This is a criminal act, an act of war,” Salvini said.

The German rescue group said Rackete did what was necessary to get people to safety. In a statement, Sea-Watch Chairman Johannes Bayer said Rackete “did exactly the right thing.”

“She upheld the law of the sea and brought people to safety,” he said.

According to a description of the events on the Italian news service ANSA, people from Lampedusa were camped out near the port and argued over how the standoff had been handled.

ANSA reported that an Italian government boat had “attempted several times” to prevent Sea-Watch 3 from docking but had aborted the effort to avoid being trapped between the dock and the German vessel.

“It looks like the motorboat managed to flee. But that said, this could still be an attempt to commit violence,” said Francesco Munari, a professor at the Genoa Institute of International, European and Maritime Law who cited portions of the Italian navigation code. “And that would lead to penalties, though diminished ones.”

As of Saturday morning, Rackete was under house arrest and facing charges that could lead up to 10 years in prison. Italy said the 40 migrants would be redistributed to five European countries — France, Finland, Luxembourg, Portugal and Germany — in a diplomatic deal.

The case of Sea-Watch 3 had dominated Italian news broadcasts for several days after Rackete announced on Wednesday that she was taking the ship to Italian territory.

But Sea-Watch was stopped just outside the harbor and remained off the island for several days, hoping for a green light to dock.

Before sunrise Saturday, Rackete said in a video posted to Twitter that Italian authorities had “notified us that they will not help to bring the rescued off the ship. That means we are still waiting for a solution that is not in sight so far.”

“Therefore,” Rackete said, “I have decided to enter the harbor, which is free at night, on my own.”

Stefano Pitrelli contributed to this report.