Charlie Hales and Jefferson Smith swept past Eileen Brady in Tuesday's primary for Portland mayor, advancing to a runoff in the November general election in one of the most expensive and competitive races in city history.

The results marked a stunning turnaround for Brady, who raised almost $1.2 million in her first bid for elected office, far more than Hales or Smith. She was the front-runner for months before losing steam in the past two weeks as Smith surged.

Tuesday's statewide primary also saw voters eject two incumbent state lawmakers, choose retired judge Ellen Rosenblum as the Democratic nominee for attorney general and approve tax measures for David Douglas schools and Multnomah County libraries.

Statewide, turnout appeared to be below 40 percent, making it the worst turnout for a presidential primary in modern state elections history. In Multnomah County, about 31 percent of eligible voters cast ballots.

In the hotly contested mayoral race -- 23 candidates were on the ballot, but only Hales, Smith and Brady were considered contenders -- Hales attracted the most votes from the get-go. At 10:30 p.m., he had 38 percent of the vote, compared with 29 percent for Smith and 24 percent for Brady.

Now voters in November will choose between two men with similar views but different styles. Both are pro-schools, pro-environment, pro-bike Democrats.

But Hales, 56, has more experience in city politics: He served as Portland city commissioner from 1993 to 2002, when he left to join a private engineering company. In the primary, he ran as the candidate who would attend to basic services first, stepping in as a leader on Day One.

Smith, 38, a state representative from east Portland, founded the populist Bus Project that aims to involve young people in politics. He sought to position himself as the candidate who could bridge Portland's diverse communities, tweaking the city motto to make Portland "the city that works -- for everyone."

Michael Grossman, a Seattle political consultant who has worked on Portland City Council races, said their views are so similar, the final outcome could come down to how voters view their character.

"This is a race of style rather than a race of substance," he said, calling it a match-up of "the gray-haired man and the wild-eyed kid."

Tuesday night at his Southeast Portland campaign headquarters, Hales celebrated with supporters and said he was surprised at how far ahead he was.

"We tried to really hear where people are to craft a future policy and direction for the city that's based on its hopes and needs," he said.

Smith, whose supporters gathered at the Bossanova Ballroom on East Burnside, stayed out of view until after 9 p.m., then spoke for only a few minutes. "I knew when I got in I wasn't famous for a supermarket and I'd never been elected citywide," he said, referring to Brady's ties to New Seasons. "I can understand why there are folks who said we didn't have a chance."

Brady emerged at her party aboard the Portland Spirit, docked at the waterfront, about 8:15 p.m. to cheers of "Eileen!" from a crowd of about 150. As she stepped on the stage 15 minutes later, she gave a fist pump and appeared upbeat, saying, "We're keeping the faith," and inviting supporters to stay for more results.

But by about 9:45 p.m., after new stats kept her in third place, she told the crowd that she had called Hales to offer congratulations while saying, "I hope to be in the runoff with him." But about 11:15, she conceded.

The loss was a tough one for Brady, who had long been considered a front-runner and who picked up endorsements from the Portland Business Alliance, labor unions and several state legislators on the strength of her sustainability advocacy and role in founding New Seasons.

Still, the race was tough to gauge all along because so many voters remained undecided, even in recent days. As a result, all three candidates campaigned furiously, making calls, knocking on doors and shaking hands.

Brady focused mostly on jobs in her campaign, declaring on an Oregon Public Broadcasting program in April that she would twist a well-known "Portlandia" phrase to "Put a job on it!"

Grossman, the consultant, said an appealing message may not have been enough; voters needed to believe she was a credible messenger, too. "Voters look at the whole package," he said.

Together, Hales, Smith and Brady raised more than $2.5 million -- a city record.

All three candidates maintained a civil tone leading up to the primary.

But the two-way race is likely to be fiercer as Hales and Smith seek to draw sharper contrasts. The general election, with a presidential election on the ballot, also will attract more voters and bring out younger and more liberal voters, local pollster Tim Hibbitts said.