They marched, they ran, and on Election Day, they won.

Women led a parade of victories and unexpected upsets Tuesday to win control of the House for the Democrats.

It was the culmination of two years of anger, frustration and activism driven by women appalled by Donald J. Trump’s election and presidency. Women poured into grass-roots groups determined to regain Democratic control of Congress and flooded organizations that trained them to run for office. As candidates, women broke the rules and upended conventional political wisdom. As activists, they expanded the definition of women’s issues beyond education and reproductive rights to include health care, immigration, gun violence and the environment.

It was a litany of historic firsts, most of them by Democrats: In Massachusetts, Ayanna Pressley became the first woman of color in her state’s congressional delegation. Rashida Tlaib in Michigan and Ilhan Omar in Minnesota will be the first Muslim women in Congress. Sharice Davids toppled a Republican man in Kansas and Deb Haaland prevailed in New Mexico, becoming the first Native American women elected to Congress. In Tennessee, Marsha Blackburn, a Republican, became the state’s first woman elected to the Senate.

But several prominent women were also defeated — Senator Claire McCaskill lost to Josh Hawley in Missouri, Amy McGrath lost a closely watched House race in Kentucky, and Senator Heidi Heitkamp lost her re-election race in North Dakota. Stacey Abrams of Georgia, who had hoped to become the first black woman in the country to be elected governor, was trailing her Republican opponent, Brian Kemp.