As summarized on Wikipedia:
A few minutes after 7 pm, she surfaced a few hundred yards off a beach 10 miles (16 km) west of Santa Barbara, California, within the Ellwood Oil Field. Over 20 minutes, she fired about 17 shells from her 14 cm gun at the giant Richfield aviation fuel storage tanks on the blufftop behind the beach.
According to a history of the Richfield Oil Company by Charles S. Jones, as cited in Robert Goralski’s World War II Almanac: 1931-1945, (1981, Bonanza Books) the shelling did about $500 in damage and was an act of revenge by the sub's captain, Kizo Nishino.
While Nishino was commanding a Japanese oil tanker picking up crude at Ellwood in the late 1930s, he slipped on a path up from the beach, fell into a cluster of cactus, and while his American hosts were suitably embarrassed for him, a group of workers at a nearby rig couldn't contain their laughter.
Apparently, he never quite got over that.
The shots were mostly wild, one landing more than a mile inland. Nonetheless news of the shelling triggered an invasion scare along the West Coast.
The following night, the anti-aircraft defenses in Los Angeles exploded into action in response to an imagined invasion (later to be known as the Battle of Los Angeles, against a supposed UFO). During a 30-minute fusillade, guns hurled 1,440 rounds of 3-inch (76 mm) and 37 mm ammunition into the night sky, and about ten tons of shrapnel and unexploded ammunition fell back on the city.
More at MilitaryMuseum.org.
Image: Japanese propaganda post depicting the submarine I-17 shelling Ellwood. Japanese captions: “Our Submarine bombarding the coast of California” “Artwork by Chuichi Mikuriya, Navy Battlefield Artist"
Image: El Capitán Wild Bill Kelso having a time of it in the cockpit of his P-40 Warhawk in Steven Spielberg's comedy 1941 (1979). The movie depicts hilarity in the wake of a Japanese invasion scare along the California coast.