WASHINGTON—The Senate on Tuesday narrowly defeated legislation that would have approved the Keystone XL pipeline, delivering a political setback to Sen. Mary Landrieu, (D., La.), who had pushed for the vote as a way to show political clout in her Senate runoff race against Republican challenger Rep. Bill Cassidy.

The vote was 59-41, with Ms. Landrieu, a three-term senator who chairs the Senate Energy and Natural Resources Committee, falling one vote shy of the 60 needed to pass the legislation, despite an impassioned plea...