Two whales that took a wrong turn and swam 144 kilometres inland to California's capital were heading back toward the Pacific Ocean on Sunday, according to the Coast Guard.

The humpback mother and her calf started moving southwest and were about eight km back down the Sacramento River late Sunday afternoon, Petty Officer Brian Leshak said.

The wayward pair were being followed by nine vessels carrying Coast Guard officers and wildlife officials to make sure they did not reverse course.

"Nothing triggered it. They just started moving on their own," Leshak said.

Jim Oswald of the Marine Mammal Center said the whales' change in direction might have been spurred by tug boats. "The tugs were out in the basin and the whales decided to follow them. They've been on the move," he said.

If the whales maintain their current speed and direction, the pair would be just east of San Francisco Bay some time after midnight, Leshak said.

"We have no estimate past that, but right now they are in the deep channel area moving along pretty good," he said.

Thousands of spectators watched the whales swam looping 800-metre laps Saturday around the Port of Sacramento. More people lined the banks of the river Sunday to get a glimpse of the retreating whales.

The whales still have a long way to go and obstacles to overcome if they maintain their course. Officials said there are sloughs leading to muddy deltas that could trap the injured whales, which appear to have been wounded by a ship's propeller.

The whales also will have to make their way through the pylons of four bridges to reach the bay and will have to swim under the Golden Gate Bridge to reach the ocean.

Carrie Wilson, a marine biologist with the California Department of Fish and Game, said boats have been positioned at the mouths of tributaries where the whales could possibly go off course. The human escorts will bang pipes and hammers underwater to discourage the whales from going off course again, she said by phone Sunday from the deck of a boat following the pair.