Poring over the logs of hundreds of voyages he made into San Francisco and Suisun bays, tugboat captain Kevin Bartoo knew something was wrong.

The numbers were just too low. He knew he had mined more sand than the logs showed.

It was not the first time he had seen the discrepancy. Once, in his employer’s office, he was offered a brief look at the books.

“All of a sudden, I realized now I have documentation of what I saw,” Bartoo said.

It was seven years ago and Bartoo, dismayed and anxious about the recent change in ownership at work, decided to call the agency that issues leases and collects royalties from sand companies.

That phone call to the California State Lands Commission set in motion six years of litigation and the discovery of what prosecutors say was a taxpayer rip-off amounting to millions of dollars.

Beginning in the early 1990s, prosecutors said, the companies systematically underreported the amount of sand they mined, built a pricing structure that hid profits from the state and stole sand by mining well outside the areas leased to them.

To prosecutors, it was outright fraud and theft.

The companies denied wrongdoing and said an audit done after Bartoo called state officials seemed to indicate they were complying with lease requirements. But in a settlement approved Dec.6 in Contra Costa Superior Court, they agreed to pay $42.2million.

Bartoo, 48, got $12million of that amount, making the self-described “sand pirate-turned-whistle-blower” the recipient of the second-largest payout ever under California’s whistle-blower law.

Most whistle-blower cases involve insiders, like executives or accountants, with access to sensitive documents or knowledge of conversations that take place behind closed doors, prosecutors said.

The sand pirates case was different. It was cracked by a tugboat captain, described by attorneys as a blue-collar guy with a knack for putting things together.

“This guy is a rough-around-the-edges, waterfront tugboat captain,” said Assistant Attorney General Christopher Ames. “He’s not your guy sitting in the office, wearing a tie and having lunch with the Rotary Club.”

The deceit, state lawyers said, was largely uncovered by Bartoo and his lawyers, former federal prosecutors Wayne Lamprey and Francine Radford, and state prosecutors.

By calculating royalties in a way that ensured payments to the state remained relatively flat, even during the economic boom of the 1990s, the companies short-changed the state out of millions.

“The price of sand went up and up, but the state wasn’t sharing in that because of what these companies were doing,” said Lamprey, one of Bartoo’s lawyers.

Jeffrey Ross, a lawyer for the defendants, said the amount of sand mined outside of lease areas and the amount of alleged underreporting were small. And company officials were led to believe their pricing practices were appropriate after the State Lands Commission audited leases in 2000 and 2001, he said.

“Why didn’t that come to light when there was an audit?” Ross asked.

Ross questioned why Bartoo got such a large share of the settlement, but state lawyers said the irregularities likely would never have come to light without Bartoo’s involvement.

Ames, the state’s lawyer in charge of prosecuting whistleblower cases except those that involve MediCal fraud, said Bartoo’s unusually high share of the settlement — 27 percent — was due to his key contributions to the case.

“We probably would not have received dollar one if he didn’t do this,” Ames said.

The case involved two sand-mining companies, their on-shore affiliates and a global construction materials powerhouse called Hanson Aggregates that bought the other companies in 1999. Hanson has its regional headquarters in Pleasanton.

Bartoo told state officials that companies were underreporting the amount of sand they were taking, and therefore probably underpaying royalties.

But other inconsistencies also bothered him. He had heard figures that led him to believe the companies’ profits were excessive.

“If there was that much money in sand, why wasn’t there more competition?” he wondered.

At the time, he was unaware of the California False Claims Act, the 1988 state law modeled on a Civil War-era federal law meant to encourage employees to come forward with information when taxpayers are being scammed.

A staff member at the commission told him about the law, and he eventually hired lawyers and spent the next year investigating and documenting the companies’ actions.

“The risk that these guys take and the heat they take as whistleblowers is no small thing,” Ames said.

In at least one case, Hanson corrected the sand mining practices of the companies it bought before Bartoo’s allegations came to light, suggesting that officials knew they were wrong and fixed the problem.

Bartoo said he and others routinely mined in areas that were not leased to the companies because that’s where supervisors told them to go and because they were unaware of lease boundaries.

“Our mining was strictly driven by quality of material,” Bartoo said. “As far as we knew, it was all fair game.”

But after it bought the other companies, Hanson required the crews to stay within lease boundaries.

Meanwhile, court papers show Hanson continued calculating royalties in a manner that lowered payments to the state until 2004, after the lawsuit was filed.

Court papers say that since the early 1990s, one of the companies began selling sand at one price to on-shore affiliates, which would then sell the sand to customers at a higher price, in some cases for more than three times as much.

The companies used the lower figures to calculate royalty payments, depriving the state of significant revenue.

The companies also structured the price of sand sold directly to third parties to include a line item for the sand itself, with other charges such as transportation added on.

But the companies used the line item for sand only to calculate royalty payments.

“The effect of these changes was to reduce the royalties paid to the state, although the total amounts invoiced to the customers increased,” Contra Costa Superior Court Judge Terence L. Bruiniers ruled last year in the first of two trials.

Bruiniers’ order was mixed, endorsing neither the state’s nor the companies’ interpretation of the leases. But he did rule that the companies’ pricing structures were unreasonable.

Bartoo said he has no specific plans for the money he will receive. And he doesn’t even sound excited about his pending wealth.

Instead, he comes across as weary and philosophical. Years of frustrating litigation and the sometimes hostile reactions from co-workers wore on him. Bartoo, who grew up in the Oakland hills dreaming about working on the Bay, said he is more interested in owning his time than anything else.

“The overall experience to me was disillusioning,” he said.

Though no longer employed directly by Hanson, Bartoo has been doing the same work for a contractor.

“Being a whistle-blower is not easy, but it is one of the few effective remedies available to ordinary citizens for stemming corporate greed,” he said.

His advice for would-be whistleblowers?

“Be certain you’re right and be certain it’s egregious,” he said. “You have to maintain the high ground and you better have maintained it all your life. … I’m convinced you can’t do it for the money. You have to do it because it’s right.”

BERKELEY — The leader of an “alt-right” group based in Vancouver, Washington, is set for a 2 p.m. rally at Sproul Plaza at UC Berkeley despite the cancellation of Free Speech Week events that were planned by a conservative student group and political provocateur Milo Yiannopoulos. Joey Gibson, the self-styled leader of Patriot Prayer, said in a video he posted...