WATERBURY — Simsbury’s Mary Glassman edged out Waterbury’s Jahana Hayes for the Democratic Party endorsement in the race for U.S. Rep. Elizabeth Esty’s 5th District seat, at Monday’s Democratic nominating convention.

But Hayes and Glassman will battle again in the mid-August Democratic primary to see which candidate will challenge Republicans for what is traditionally Connecticut’s most competitive congressional seat.

“When Elizabeth Esty decided not to run, I stepped up — I didn’t wait,” Glassman said shortly before delegates voted at Crosby High School in Waterbury. “There is no time to wait, there is too much at stake for the people of the 5th District and the people of the United States.”

Glassman, a former Simsbury first selectman, has impressed Democrats with her organization, raising more than $100,000 since jumping into the race in early April. Hayes, the 2016 National Teacher of the Year from Waterbury’s John F. Kennedy High School, has also impressed party leaders, including U.S. Sen. Chris Murphy, who encouraged her to run.

Both candidates sought the party’s nomination to replace Esty, a three-term incumbent who dropped her bid for a fourth term earlier this year after admitting she covered up an office abuse scandal.

Delegates from the 41 cities and towns that make up the 5th District gave Glassman 173 votes, just enough needed to meet the 50 percent threshold to win the nomination.

Hayes received 167 votes, more than the needed 15 percent to earn a spot in the Aug. 14 primary, when the 5th District’s 133,000 Democrats will have the final say about who runs in the November election.

“My greatest gift to you is my lack of political experience,” said Hayes, who was treated to a rousing performance before the convention by the 30-member Berkeley Heights youth drum corps. “Because when I go to Washington I will work for you and for no one else.”

A state Democratic official said the candidates had recharged the party.

“We are excited about the enthusiasm that this race has generated, and we are excited about the candidates,” said Christina Polizzi, communications director of the state Democratic Party.

Monday’s nominating convention comes three days after Republicans nominated former Meriden Mayor Manny Santos at the GOP convention at Foxwoods Resort Casino. Republicans also gave enough support to political newcomer Ruby O’Neill of Southbury to force a GOP primary in August.

The district stretches from greater Danbury to the Massachusetts border, and as far east as New Britain.

Democrats will nominate candidates for governor and statewide offices on Friday and Saturday in Hartford.

There is more attention on the 5th District this year because of Esty’s surprise withdrawal from the midterm elections — a decision that her office insists she is sticking to.

Esty, who had $1.5 million raised when she dropped her re-election campaign in early April, admitted it was a mistake to cover up sexual harassment and abuse allegations against her former chief of staff. Esty admitted that she compounded her mistake by recommending her chief of staff for a job with Newtown-based Sandy Hook Promise.