One of the Buchanan County deputies had life-threatening injuries and the other was in serious condition, state police said.
Buchanan County Sheriff Ray Foster called the shooting "one of a kind" for his department but declined to say anymore.
The owner of Roger's Service Center in the southwestern Virginia community of Vansant told police that his business was being robbed and he had blocked the suspect's vehicle with his own.
State Police Sgt. Steve Lowe said when deputies and state police arrived about 2 p.m., someone started shooting at them. Two deputies were hit and died at the scene. Police did not release what sort of weapon was used, but Lowe said the suspect shot from long range.
The other two deputies were shot when they arrived at the salvage yard.
State police and other officers found the suspect about two hours later and after "some sort of engagement" they shot and killed him, Lowe said.
"I'm not sure what the confrontation was when they encountered him," Lowe said. "Apparently he was identified as the right person."
Lowe said he didn't know if the man fired on police, or if he was armed at the time.
Christina Stiltner lives across the street from the salvage yard and had just walked into her home with her 10-year-old son when she heard "pow, pow, pow."
She opened her front door and saw one deputy run into a neighbor's yard. She heard another "pow" and the deputy went down. He was one of the injured, she said.
"It scares you so much," she said. "I sat there thinking 'what's the number to 911'? It shocked me so badly, I didn't know the number to 911."
Stiltner, who works at a gas station and restaurant, said she knew all the deputies involved in the attack because they would often stop by the store. State Police did not release their names or that of the suspect and they may not be given until Monday.
Stiltner said she wasn't allowed to return to her home seven hours after the shootings ended. Several other residents were out of their homes late Sunday.
"This is a laid-back community. Everybody knows everybody," said Tivis O'Quinn, 68, who has lived in town of 1,000 for 40 years and operates a business less than a mile from the salvage yard. "Nothing like this ever takes place, except for the law school shooting."
In January 2002, a student opened fire on the Appalachian School of Law campus after learning he had failed out of school. The school's dean, a professor and a student were killed in the attack. Three other students were wounded. The shooter, Peter Odighizuwa, pleaded guilty and was sentenced to life in prison.
Vansant is a former coal mining town in the mountainous region of southwestern Virginia. O'Quinn said the community experiences "little petty thefts now and then," but nothing like what occurred on Sunday.
On display in O'Quinn's office was a 2011 calendar of the Buchanan County Sheriff's Department. The photo features the department's 47 members, including Foster and 24 uniformed deputies.
According to the website The Officer Down Memorial Page, the last Buchanan County sheriff to die in the line of duty was in 1975 of a heart attack. The website lists four on-duty deaths for the department since 1905. The last by gunfire was in 1964.