WASHINGTON—The House on Thursday narrowly passed a Republican-written bill that reauthorizes farm programs while also imposing controversial new work requirements on food-stamp recipients, acting on legislation that is important to a critical GOP constituency before the midterm elections.

The bill passed on a 213-211 vote. The Senate is expected to vote next week on its own version of the bill, which funds crop insurance and payments to farmers when commodity prices or revenues drop below set levels. The measure, estimated...