AMHERST, N.Y. —A Democrat won election Tuesday to a congressional seat from a traditionally Republican district in western New York, an outcome that will be studied for clues to how voters are viewing the budget battles in Washington.

Republican candidate Jane Corwin had endorsed a plan passed by GOP House members last month to overhaul Medicare, drawing attacks from her Democratic rival, Kathy Hochul.

Ms....