Houston police responded to the gas station on Cullen near Dreyfus around 12:30 Friday morning.
Authorities say the suspect approached the officer while he was conducting a traffic stop. The suspect was not involved in the stop in any way.
Police say the suspect then ran up to the officer and stuck him in the head with a 35 inch pipe.
The officer then drew his pistol, but the suspect continued to approach him with the pipe.
That's when authorities say the officer fired several rounds.
Both the officer and the suspect were taken to the hospital where they are both expected to be okay.
"There's something going on in our country right now, in our city with people just attacking an officer with that weapon while he's just conducting business, calmly conducting business," Houston Police Chief Art Acevedo said.
Acevedo said the two men who were detained in the back of the officer's patrol car during the stop actually tried to warn the officer, but he didn't hear them in time.
SEE ALSO: Activists call for release of body camera video in deadly officer-involved shootings
Follow TJ Parker on Facebook and Twitter.