Hackers broke into the computer system of a facility that treats water for about 15,000 people near Tampa, Florida and sought to add a dangerous level of additive to the water supply.
The Pinellas County Sheriff said the attempt was thwarted on Friday.
The hackers remotely gained access to a software programme, named Team Viewer, on the computer of an employee at the facility for the town of Oldsmar to gain control of other systems, said Sheriff Bob Gualtieri.
"The guy was sitting there monitoring the computer as he's supposed to and all of a sudden he sees a window pop up that the computer has been accessed," Sheriff Gualtieri said.
"The next thing you know someone is dragging the mouse and clicking around and opening programmes and manipulating the system."
The hackers then increased the amount of sodium hydroxide, also known as lye, being distributed into the water supply.
The chemical is typically used in small amounts to control the acidity of water, but at higher levels is dangerous to consume.
The plant employee alerted his employer, who called the sheriff. The water treatment facility was able to quickly reverse the command, leading to minimal impact.
Oldsmar Mayor Eric Seidel said in a press conference that the affected water treatment facility also had other controls in place that would have prevented a dangerous amount of lye from entering the water supply unnoticed.
"The amount of sodium hydroxide that got in was minimal and was reversed quickly," Sheriff Gualtieri said.
The affected water treatment facility is a public utility owned by the town, he explained, which has its own internal IT team.
Oldsmar is about 25km northwest of Tampa and has about 15,000 residents.
Team Viewer, which says on its website that its software has been installed on 2.5bn devices worldwide, enables remote technical support among other applications.
The FBI and Secret Service have been called in to assist in an investigation. Sheriff Gualtieri said he does not know who is responsible for the cyber attack.
"The important thing is to put everyone on notice, " he said. "This should be a wake-up call."