WASHINGTON — The surprise defeat of the farm bill in the House on Thursday underscored the ideological divide between the more conservative, antispending Republican lawmakers and their leadership, who failed to garner sufficient votes from their caucus as well as from Democrats.

The vote against the bill, 234 to 195, comes a year after House leaders pulled the measure off the calendar because conservative lawmakers demanded deeper cuts in the food stamp program and Democrats objected. This year’s measure called for more significant cuts than the Senate bill, but it still did not go far enough to get a majority in the House to support an overhaul of the nation’s food and farm programs. Sixty-two Republicans, or more than a quarter of the caucus, voted with Democrats to defeat the bill.

The failure was a stinging defeat for Speaker John A. Boehner of Ohio, who continues to have trouble marshaling the Republican support he needs to pass major legislation. Without the solid backing of his party, Mr. Boehner has to rely on some Democratic support, which deserted him Thursday.

Mr. Boehner was unable to secure the votes of a number of recently elected and strongly conservative lawmakers who were averse to cutting deals on legislation like the farm bill. Traditionally, the farm bill has passed easily with support from urban lawmakers concerned with nutrition spending and rural members focused on farm programs. But conservatives said they were more driven by a desire to shrink the size of government through spending cuts, not expand it though crop insurance subsides to rich farmers.