The mayor had gone to the Wisconsin State Fair on Saturday with his children and niece. As Barrett walked to his car, he heard a woman screaming for someone to call 911, police said.
"The mayor stopped and said something like, 'Let's all cool down here, I'm going to call 911,"' the mayor's spokesman Patrick Curley said. "He said it one or two times according to him. When he took out his phone, that's when the suspect attacked him."
The suspect hit him in the head and torso with a metal pipe. Barrett apparently fought back, fracturing his hand when he punched the suspect.
"I think he hit the guy," Curley said. "I don't know where, but it was hard enough, whatever he hit, to fracture his hand."
The suspect then fled the scene. Authorities said they were seeking a person who has a criminal arrest record, police said. The woman was uninjured.
The mayor, who did not ask for security to accompany him to the fair because he wasn't on official duty, underwent successful surgery Sunday on his fractured right hand and also had cuts on his head and lip stitched up, Curley said.
"He's in stable condition and all his vitals are good," Curley said. "I saw him an hour ago and we had a very nice conversation."
He will likely remain in the hospital through Monday, Curley said, adding that he wasn't aware of any pending surgical procedures.
Gov. Jim Doyle said he also visited Barrett at the hospital on Sunday morning and found him in "good spirits and looking good considering what happened."
"The mayor's heroic actions clearly saved a woman and others from harm," Doyle said in a statement.
Under the city's line of succession, Common Council President Willie Hines would take command if the mayor were incapacitated. Curley said he briefed Hines on Sunday morning but didn't expect a transfer of power would be necessary because Barrett "is engaged, he's conversational."
Barrett was already planning to take this week off for a family vacation, Curley said.
The mayor's only regret about the incident is that his family was there to witness what happened, Curley said.
"He said it was hard because his kids and niece were there at the time of incident," Curley said. "He knew he had to (intervene). It was the right thing to do."