MONTGOMERY, Ala. — The Alabama House of Representatives narrowly approved Gov. Robert Bentley’s proposed state lottery Thursday night after 10 hours of contentious debate and two vote attempts.

Legislators clapped and cheered as the bill passed shortly before midnight on a 64-35 vote, exceeding the 63 votes required to pass the chamber. The bill now moves to the Alabama Senate where senators must decide whether to go along with mostly minor House changes to the legislation.

The Republican governor, seeking to end the Deep South state’s historic opposition to gambling as a revenue source, proposed a lottery as a way to provide money to the state’s perpetually cash-strapped Medicaid program. Alabama would become the 45th state with a lottery if lawmakers and voters approve the idea.

“We came out with a victory from the House, not for us, a victory for the people of this state,” Bentley said at a news conference early Friday. “It’s about the one million people who depend on Medicaid in this state.”

Legislators worked late into the evening during a contentious debate — peppered with arguments about the impact on the poor, the best way to use lottery proceeds and if lawmakers should also allow casino gambling.

The evening brought a bitter reversal of fortune for lottery opponents who thought they had defeated the measure when the initial vote failed 61-37. Supporters quickly won a reconsideration motion, wagering they could garner enough votes on the second attempt.

“I’m disappointed, extremely disappointed,” said lottery opponent Rep. Rich Wingo, R-Tuscaloosa. “This is the legacy this group is going to leave behind. We’ve brought gambling into the state of Alabama. This is on us. I’m ashamed of that.”

Wingo argued that lotteries have failed to solve budget shortfalls in other states while preying upon poor residents’ hopes of striking it rich with a winning ticket.

Supporters contended Alabama is bordered on three sides by states with lotteries and is getting no benefit from the tickets Alabama residents travel across state lines every day to buy.

“I can tell you for a fact that thousands — and I’m talking about thousands of people up in my area — go over to Tennessee and they buy tickets,” said Rep. Kerry Rich, R-Albertville.

House members made minor changes to the bill, including defining the lottery as paper tickets — an attempt to prohibit electronic lottery terminals — and earmarking a small sliver of lottery proceeds to rural fire departments. Lawmakers voted down other attempts to broadly change the bill to allow casino gambling or steer more lottery proceeds to education.

The final vote came after hours of nervous counting from both sides trying to gauge support.

The governor projected a lottery would raise $225 million each year. The bill would steer 10 percent of proceeds to education and 90 percent to the general fund budget, with the first $100 million specifically going to the Alabama Medicaid Agency.

Bentley is seeking the first statewide referendum on a lottery since 1999 when voters rejected a lottery proposed by then-Gov. Don Siegelman.

Tensions were high over some of the tactics as the House began debate. The front desk of the House was jammed with telephone calls after Bentley gave out his Capitol office phone number and urged people to get in touch with their legislator. A pamphlet anonymously distributed to lawmakers in violation of House rules said the state risked losing God’s blessing. The debate found its way into the day’s opening prayer as Rep. Thomas Jackson, D-Thomasville, said outsiders were trying to block a vote on a lottery. “God is watching and Jesus knows the evil that is going on in your heart, and there is no escape if you deny the least of these the opportunity,” Jackson said.

Supporters were aiming to get the measure on the Nov. 8 ballot, hoping to persuade Secretary of State John Merrill to add the measure if it wins final approval. Merrill said the Wednesday deadline had passed, but Attorney General Luther Strange said Merrill had the discretion to add it through Friday.

Bentley said other issues, including another constitutional amendment that could preserve the legality of some local laws, might persuade Merrill to accept ballot changes.