With all precincts reporting, Gordon garnered 56.1 percent of the vote. Yang finished second with 29 percent of the vote.
Because of California's new primary rules, the top two vote-getters automatically advance to the general election in November.
Yang, 35, of Menlo Park, is a software engineer.
Also running were Joseph Antonelli Rosas, 22, of Sunnyvale, a network security adviser who has no party affiliation; and Geby Espinosa, 47, of Mountain View, a Democrat and a small business owner. They received about 4 percent and 10 percent of the vote, respectively.
Gordon, a Menlo Park resident, now represents District 21, which includes Menlo Park, Atherton, Woodside, Portola Valley, East Palo Alto, and Palo Alto. But with redistricting, the same area will become part of District 24. The district has been reshaped to encompass areas including Mountain View, Sunnyvale, and most of the San Mateo County coastside from El Granada south.