A security guard and a gunman were both killed in an exchange of gunfire in front of the US consulate in Jeddah on Wednesday, Saudi police said.
"At 6:45 pm (1545 GM) a man stopped in a car in front of the consulate building and got out with a weapon in his hand," the official SPA news agency quoted a police spokesman as saying.
"Security forces reacted... resulting in an exchange of fire that killed the assailant," it said.
A Nepalese security officer was wounded and later died.
The attack occurred as Saudi Arabia hosted some 1.8 million Muslim faithful for the annual hajj pilgrimage in the holy city of Mecca, some 70 kilometres (44 miles) from Jeddah.
The US consulate in the coastal city of Jeddah on the Red Sea has been the target of previous attacks, one on July 4, 2016, American Independence Day, when a suicide bomber blew himself up.
In December 2004, another attack left five people dead.