SEATTLE  A former Sierra Club leader who rode his bicycle to campaign events and relied heavily on volunteer support claimed a narrow and surprising victory on Monday in the race for mayor of this environmentally friendly city.

“You cared, you believed, and we’ve got a lot more work to do,” Mike McGinn told supporters after the city’s mail-in election showed him winning 51 percent of the vote, by a margin of 4,939 votes out of about 190,000 cast in the mayor’s race.

He was met by the same chant he heard on the campaign trail: “We like Mike!”

His opponent had conceded a few minutes earlier.

Image Mike McGinn, who received 51 percent of the vote, relied heavily on volunteer support. Credit... Stephen Brashear/Getty Images

Mr. McGinn, who was outspent more than 3 to 1 and did not receive endorsements from major political and business leaders, defeated Joe Mallahan, a vice president with T-Mobile who contributed more than $200,000 to his own campaign.