JAKARTA, Indonesia -- Passengers trapped for a night on a stricken ferry off the Indonesian island of Sulawesi were rescued early Wednesday, officials said, as the death toll rose to 31 with three people missing and believed drowned inside the vessel. The latest in a succession of boat tragedies in Indonesia began on the same day that officials called off a search for 164 people presumed drowned when a wooden ferry sank on June 18 in a deep volcanic crater lake on the island of Sumatra.

The Sulawesi ferry, with 139 passengers aboard according to its manifest, began sinking Tuesday afternoon in rough seas. In a desperate bid to save lives, the vessel's captain steered it toward shore, grounding it between 985-655 feet from land.

Indonesia's director-general of sea transportation, Agus Purnomo, said in a statement that people trapped on the ferry overnight were rescued early Wednesday.

Get Breaking News Delivered to Your Inbox

He didn't specify how many but said the captain and the boat owner were the last two people to leave the vessel.

Amiruddin, chief of the South Sulawesi search and rescue agency, said there were 164 people on the vessel including crew. Amiruddin, who uses one name, said 130 survived.

"We are still searching for three others who we strongly believe are still inside the ship," Amiruddin said.

Photos released by National Disaster Mitigation Agency on Tuesday showed passengers clinging to the listing vessel as others descended into the heavy seas using ropes hung over its side. Most appeared to be wearing lifejackets.

Purnomo credited the captain's actions with helping to save lives.

The 159-foot-long vessel, carrying several dozen vehicles including a bus and trucks, was on its way to Selayar island, just south of the main Sulawesi island, from the port of Bira when it began taking on water.

Local residents and relatives of missing passengers from a ferry accident on Lake Toba, wait on the dock at Tigaras Port in Simalungun, North Sumatra, Indonesia June 19, 2018. REUTERS

Ferry tragedies are common in Indonesia, an archipelago of more than 17,000 islands, with weak enforcement of safety regulations often to blame.

The Lake Toba sinking two weeks ago was the worst in about a decade.