By a thin 56-42 margin, the Senate rejected a Republican measure that would have allowed construction on the Keystone XL pipeline to begin immediately. Senate Majority Leader Harry Reid agreed on Wednesday to let the amendment come to the floor as part of an effort to break a Republican filibuster on the overall transportation bill, but a sixty-vote requirement was attached.

North Dakota Senator John Hoeven offered the measure, which would have removed the White House from the Keystone approval equation entirely. In 2004, President George W. Bush signed an executive order establishing the current presidential permit process for oil pipelines that cross an international border, which did not previously exist. Hoeven’s amendment would negate that order.

When he announced the amendment would come up for a vote, Reid expressed confidence it could be defeated, and told reporters earlier today that the GOP didn’t have the votes. But victory for pipeline opponents was never assured—forty-five Republicans were assuredly going to vote for Hoeven’s amendment, and many “moderate” Democrats had been wavering in recent days. (There are forty-seven Republican Senators, but Mark Kirk is recovering from a stroke and John Thune’s mother just passed away).

Environmental and progressive groups flooded Senate offices in the past twenty-four hours, with over 800,000 messages against the Hoeven amendment. President Obama also personally called wavering Democrats and urged them not to support the provision.

Unlike the Keystone provision that made it into the payroll tax cut deal late last year, the Hoeven amendment could have actually kicked off immediate construction of the pipeline. The earlier measure simply forced the White House to make a decision within two months—which it did, and denied the permit. But by removing the administration from the permit process, TransCanada could start building in the United States immediately wherever it had the appropriate state permits.

If Hoeven succeeded, Obama would have had to choose between vetoing a major transportation bill that took extensive wrangling to pass—a feat nobody on the Hill would want to repeat—or allowing Keystone to proceed. His urgent phone calls may have worked (eleven Democrats still defected), but Republicans have been hammering for it all day. Senate Minority Leader Mitch McConnell and House Speaker John Boehner blasted out multiple statements today on the issue, as they are eager to paint Obama’s opposition as both job-killing and detrimental to gas prices. (Both claims are false.) McConnell said that “frankly, it’s hard to even comprehend how out of touch [Obama] is” on Keystone, and Boehner was equally rambunctious during a press conference this afternoon:

I think the White House owes the American people an explanation. The president said this week that he wants to see lower prices at the pump—at least in an election year. But his own policies are making matters worse and driving up the cost of energy. But by “personally lobbying” against the Keystone pipeline, it means the president of the United States is lobbying for sending North American energy to China, and lobbying against American jobs.

You’ll hear these attack lines again and again leading up to the November elections, but this may have been the last opportunity Republicans had this year to actually get a Keystone measure passed.

It was a bad day overall for big energy interests in the Senate; an amendment by Senator David Vitter to open up vast offshore areas to oil drilling was defeated, as was an amendment by Senator Susan Collins to delay EPA regulations on air toxics from incinerators and industrial power plants.