ROME — A judge in Sicily on Tuesday lifted a house arrest order and freed Carola Rackete, the captain of a ship carrying rescued migrants who had been detained over the weekend after defying the Italian authorities and docking on the Mediterranean island of Lampedusa.

Captain Rackete had defended her decision to challenge Italy’s closed-ports policy and dock the Dutch-flagged Sea Watch 3, which is owned by a German humanitarian organization, by citing a state of emergency because of the growing exhaustion and desperation among the 40 migrants aboard, who were rescued from a shipwreck on June 12.

After maneuvering the Sea Watch 3 next to a pier in Lampedusa and colliding with a border patrol vessel, Captain Rackete was placed under investigation for resisting a public official and committing an act of resistance or violence against a military ship. Should she go to trial, she faces up to 10 years in prison.

Judge Alessandra Vella ruled Tuesday that Captain Rackete should not be held in a state of detention while prosecutors investigate whether there is sufficient evidence to formally charge and send the 31-year-old German woman to trial. The investigation could continue for up to two years.