Under the legalization measure, which the state House approved 61-54 before sending it on to the Senate for technical changes, gay weddings could be held in Illinois starting in June. The bill heads next to Gov. Pat Quinn, who has pledged to sign it, though it wasn't immediately clear when.
Fourteen states plus Washington D.C., allow same-sex marriage.
The road to the Illinois vote was long with a stalled attempt earlier this year, something that frustrated activists in the state where Democrats lead the House, Senate and governor's office. Chicago Democratic Rep. Greg Harris, who is the main sponsor, decided not to bring the bill for a vote in May because he said he simply didn't have the support.
Then the U.S. Supreme Court ruled to strike down a provision of the federal Defense of Marriage Act, something he said resonated with lawmakers. Backers also launched a furious campaign, hiring a union lobbyist, the former head of the Illinois Republican Party and field organizers statewide.
"To treat all our citizens equally in the eyes of the law we must change this," Harris said on the floor. "Families have been kept apart."
Debate lasted more than two hours, and the final roll call was met with hearty cheers. Supporters' speeches echoed themes of equality and civil rights with mentions of Obama, Martin Luther King Jr. and Matthew Shepard, a gay college student whose 1998 death sparked hate crime bills.
Among those celebrating were Suzie Hutton and Danielle Cook of Bloomington, who've been together for a dozen years and have a teenage son.
"We care about our kids. We care about our communities. We're involved in our church. We just wanted the dignity (of marriage)," Hutton said.
Polls show support for gay marriage has surged since 1996, when Gallup found that 27 percent of Americans backed it. Now Gallup finds the majority support giving gay and lesbian couples the right to marry.
In Illinois, the measure had backing from both the state's U.S. senators and Chicago Mayor Rahm Emanuel. It also got a last-minute boost from longtime House Speaker Michael Madigan, who serves as chair of the state's Democratic Party. The Chicago Democrat said he used the "art of persuasion" to bring on more than five votes in the last week.
"Today the Illinois House put our state on the right side of history," Quinn said in a statement. "Illinois is a place that embraces all people and today, we are an example for the nation."
Obama praised the Illinois Legislature - where he once served as a state lawmaker - saying in a statement that the matter was conducted in a way that would recognize the importance of a "commitment to religious freedom."
However, opponents - including some of the most powerful religious leaders in Illinois - have said marriage should remain between a man and a woman. A group of Chicago-area pastors vowed to line up primary challengers against some lawmakers who voted yes.
"This issue is not just about two adults and their emotional relational and financial commitment to another," said Rep. Tom Morrison, a Palatine Republican. "Redefining marriage has far reaching implications in our society."
Three Republicans joined those voting in favor, including former House Minority Leader Tom Cross of Oswego who had not revealed how he'd vote ahead of Tuesday. The representative stepped down from his leadership position earlier this year and is seeking statewide office as treasurer.
"For me, supporting marriage equality is not only the right decision, but also consistent with my belief in individual freedom, equality and limited government," Cross said in a statement.
Other lawmakers also came forward for the first time Tuesday, including Democratic state Rep. Jehan Gordon-Booth of Peoria, who wrote a newspaper opinion piece expressing her support as a matter of equality.
The bill first cleared the Senate on Valentine's Day with the support of 33 Democrats and a single Republican. Backers expressed confidence that the bill would be approved by the House in mid-March. But it took the supporters months to secure votes.
Backers of the measure never publicly discussed their vote totals, but earlier this year Madigan said the measure was about a dozen votes shy.
Although Illinois once appeared poised to become the first Midwestern state to approve gay marriage in the Legislature, Minnesota did it sooner and started holding its first same-sex weddings over the summer. Iowa allows gay marriages too because of a court ruling, not a legislative vote.
The issue caused internal conflict among Illinois Republicans as the party works to balance efforts to appeal more to younger voters, minorities and women with the more socially conservative positions of some party members.
For months, the leaders of several black mega-churches lobbied the districts of black House members with an aggressive robocall campaign against gay marriage, placing the Democratic members of the caucus in an uncomfortable spotlight. Many remained undecided until the vote neared.
Those in the black caucus who spoke out in favor called it a matter of civil rights.
"I understand a lot of pastors disagree. What I decided to do was the right thing and stand for what is right. I feel like Dr. King, fighting against inequality," said Rep. Emanuel Chris Welch, a Hillside Democrat.
The African American Clergy Coalition praised those who voted against the measure.
"We will always believe that marriage is between one man and one woman," said Bishop Larry Trotter of the coalition. "Yet we will still love the members of the LGBT community."
Illinois approved civil unions in 2011.