OTTAWA — The situation looked dire for the crew of the Atlantic Destiny. A fire first knocked out power onboard the scallop trawler and then it began taking on water. More than 130 miles away from its home port in Nova Scotia, the 144-foot-long ship was hopelessly bobbing up and down on waves 40 to 80 feet high.

But while the Atlantic Destiny ultimately sank, a joint rescue effort by Canada and the United States meant that all its 32 crew members had been rescued before it went down.

“The weather was probably some of the worst weather I have actually executed a hoist operation in,” said Cmdr. David McCown, a pilot on a United States Coast Guard helicopter that rescued 13 of the ship’s crew.

The rescue effort began when the Atlantic Density sent out a distress call on Tuesday because of the fire. Ships from the United States and Canadian Coast Guards were dispatched; the Royal Canadian Air Force sent two rescue helicopters and an airplane from Nova Scotia, while another pair of helicopters and a plane took off from a U.S. Coast Guard base in Cape Cod.

Cmdr. Aaron O’Brien, the lead officer of a Canadian Coast Guard ship, the Cape Roger, traveled overnight to reach the sinking trawler. He charged ahead for about 11 hours, buffeted by side winds of up to 90 miles an hour, navigating against the wind through rough seas that he would normally cross at a near walking pace. There was no time to waste.

“In a case like that, every moment counts,” Commander O’Brien said. “So we were hammer down as much as possible.”

The Canadian Air Force arrived first and completed the dangerous task of dropping two search and rescue technicians onto the sinking fishing ship. While one prepared the crew for evacuation, the other worked to slow down the ship’s intake of water.

The rescue began by lifting crew members put in a rescue basket into a helicopter, a maneuver that had to be coordinated with the huge ocean swells. Commander McCown said that the pilots and their crews used night vision goggles to keep an eye on the waves, sometimes the height of an apartment building, throughout the process.

Because the fishing ship’s crew had been able to stay onboard and out of the frigid water, Commander McCown said that they were mostly in good shape, if very shaken.

When his helicopter reached its weight limit with 13 members of the sinking ship’s crew, it immediately made the long flight back to Nova Scotia. When it landed, he estimated that there was only enough fuel left for another 40 minutes of flight.

Two other helicopters rescued 15 more.

One helicopter stayed behind, while the two search and rescue technicians from the Canadian military and four Atlantic Destiny crew members remained on the sinking ship in an effort to rescue it by pumping water out.

But early Wednesday morning, they too decided it was time to leave.

Capt. Malcolm Grieve of the Canadian Air Force began trying to retrieve the remaining six in an effort that proved tricky. When his helicopter lowered a steel cable to start the process, the cable wrapped around a railing on the ship and had to be immediately cut loose. As a result, all his crew could do was lower some rescue boats and first aid supplies and wait for the Cape Roger to arrive after its all-night journey.

It appeared around 7:30 in the morning.

The last people on board, including the captain, climbed down a rope ladder into an inflatable boat sent from the Coast Guard ship at about 8 in the morning. Two and half hours later, the Atlantic Density sank.

“It was a total relief off my shoulders” Commander O’Brien said of the successful rescue. “I’m just thankful that we could help someone in distress and that we could be there really at the right place at the right time.”