WASHINGTON  A federal judge in Sacramento on Wednesday upheld a California law regulating greenhouse gas emissions from cars and trucks, another in a string of legal defeats for the auto industry this year.

The ruling, by Judge Anthony W. Ishii of United States District Court, affirms a 2002 California law that would effectively force automakers to raise the average fuel economy of fleets by about 30 percent by 2016. A bill pending in Congress demands a 40 percent mileage increase by 2020.

The auto companies challenged the California law, which 15 other states say they intend to adopt, saying that it is technically and financially impossible to meet. They also argued that regulation of vehicle mileage is the responsibility of the federal government, not the states.

“We can all agree that higher fuel economy is important, but the issue here was about federal fuel economy law,” said Dave McCurdy, president of the Alliance of Automobile Manufacturers. “Under federal law, only the federal government can set fuel economy standards for all 50 states.”