A security guard made contact with the man inside Bakersfield Heart Hospital, but there was no exchange of gunfire, police said.
He then walked outside, where police, who had just arrived, shot him, Assistant Chief Greg Terry of the Bakersfield Police Department said.
The gunman, whose name has not been released, was treated at the hospital before being transferred to another one, police said.
There was no word on his condition or his motive, nor have police said what kind of gun he had or how many shots he fired.
The hospital was put on lockdown while officers looked for injured people or other threats connected to the gunman, but none were found, authorities said.
The hospital has 47 beds and specializes in cardiac care, according to its website.
Bakersfield, a city of 365,000 people. Is located about 100 miles (160.93 kilometers) northwest of Los Angeles.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.