An Uber driver shot and killed a motorist who confronted him in a case that police say was legally justified under Florida's stand your ground law.

Dashcam video shows Jason Boek, 34, swerving his truck in front of driver Robert Westlake, then jumping out and claiming to have a pistol.

Mr Westlake, 38, who had just completed training to be a police officer, fires once, fatally striking Mr Boek.

Polk County Sheriff Grady Judd said Mr Boek was a "goofball".

"Here's a message for the hotheads of the community: don't do that stuff," the sheriff said.

"Good people carry guns and they will shoot you. A lot. Graveyard dead."

Video from Mr Westlake's Hyundai Elantra dashcam shows Mr Boek's pick-up truck cutting in front of him, forcing him to stop in a dark road.

The confrontation unfolded at around 02:20 local time (06:20GMT) on Tuesday in the city of Winter Haven, 50 miles (80km) east of Tampa.

"I say something?" Mr Westlake asks.

"You know I got a pistol? You want me to [expletive] shoot you?" Mr Boek responds. He was holding an object which turned out to be a mobile phone, said police.

Seconds later, a gunshot is heard.

Sheriff Judd called the encounter a "classic stand your ground case".

The stand your ground law does not require citizens to retreat when attacked, placing the onus on prosecutors to prove that a fatal shooting was not in self-defence.

Critics say the law stokes violence and adds to America's high rate of gun deaths.

"This is a justifiable homicide all day long. You have the right protect yourself," Sheriff Judd said on Wednesday.

"This was the intent of the law," he added.

According to investigators, the incident started with a case of mistaken identity.

Mr Boek had been "stalking" his girlfriend outside a bar, the sheriff said.

When she went outside the pub to help a drunk friend get into an Uber to leave, Mr Boek mistakenly thought she was in the car, said the sheriff.

The boyfriend set off in pursuit, sending "explosive" text messages to her along the way, added the sheriff.

After the shooting Mr Westlake called 911 and attempted to perform CPR.

Sheriff Judd said that Mr Westlake had recently finished training with the police academy, and was legally licensed to carry a gun.

"The Uber driver did the right thing to protect himself and his passenger," Sheriff Judd said.