Under ranked choice voting, which applies only when more than two candidates are competing, voters list candidates in order of preference; if no candidate wins a majority in the first round, the candidate in last place is eliminated, those votes are redistributed, and the ballots can be recounted immediately until someone does.

Australia, Ireland and several American cities, including Cambridge, Mass., have used ranked choice voting for years. The Academy of Motion Picture Arts and Sciences uses it to pick the Oscar for best picture.

[Read more here about how ranked choice voting works in practice.]

In June, the state of Maine became the first to use it statewide in its primaries for governor and other offices. In November, Maine will become the first state to use it in general elections for Congress. Ranked choice voting may be on the ballot for voters in New York City to consider in 2019, and several other cities are poised to use it in coming elections in states as varied as Utah, New Mexico, Minnesota and California.

In Massachusetts, Ms. Trahan squeaked to a lead in the Sept. 4 primary in an unwieldy field of 10 candidates. Most conceded. But one, Dan Koh, the extremely well-funded former chief of staff to Boston Mayor Martin J. Walsh, came within 122 votes of Ms. Trahan, a tiny fraction of all 89,000 ballots cast. Ms. Trahan claimed victory, but Mr. Koh refused to concede.

He then requested a recount, a process that ended Monday. After all 37 municipalities had recounted their ballots, Ms. Trahan had won 18,580 votes, or 145 more than Mr. Koh. She was declared the winner with 20.9 percent of the 88,823 votes cast.