Tesla, the automaker determined to shift the world to environmentally friendly cars, has agreed to pay a fine of $139,500 over excess air pollution from its Fremont factory.

The company, based in Palo Alto, also will install a solar array on the roof of a Boys and Girls Club in San Jose, as part of the settlement with the Bay Area Air Quality Management District.

According to the district, several pieces of malfunctioning equipment at the plant emitted elevated levels of smog-forming nitrogen oxides from 2013 through 2016. The problem has since been corrected, and Tesla is now in compliance with the district’s air pollution limits.

“Although Tesla develops electric vehicles and related technologies that California needs to address global climate change, the company still must comply with all their permit conditions,” Jack Broadbent, the district’s executive officer, said in a news release.

The factory on Fremont Boulevard has had a long history, under a series of owners.

General Motors opened it in 1963, shut it down in 1982, and then reopened it two years later in a joint venture with Toyota, called New United Motor Manufacturing Inc. But that joint venture foundered in the wake of last decade’s recession, and the plant closed again in 2010. Tesla bought it later that year and started building the company’s Model S sedan there in 2012.

Tesla blamed the violations on old equipment left over from the plant’s previous incarnation. All of the offending equipment has been replaced, as the company spent more than $3 billion to update the factory.

“The majority of these violations were resolved by Tesla four years ago when we proactively brought the issue to the attention of the District,” a Tesla spokesman said in an email. “They were the result of Tesla inheriting an older building that was not up to our standards.”

Under Tesla, the factory, which now employs more than 10,000 people, has largely received a clean bill of health from the air quality district. A spokesman for the district said the company had received one prior penalty — for $1,000 — for problems related to a furnace, in 2013.

Tesla did, however, agree in 2010 to pay a $275,000 penalty to the U.S. Environmental Protection Agency for failing to obtain a “certificate of conformity,” specifying that its original electric car — the Roadster — complied with the Clean Air Act.

Tesla’s factory is known to have faced one significant fine in the past, but it came from workplace safety regulators, rather than pollution regulators. The state’s Division of Occupational Safety and Health fined Tesla $71,000 over a 2013 accident that left three employees severely burned after they were sprayed by molten aluminum at the plant.