WASHINGTON—Major trade legislation narrowly survived a key vote in the Senate on Thursday, propelling the bill toward what is expected to be a more difficult path in the House next month.

For the second time in two weeks, a handful of Democrats allied with President Barack Obama on trade policy almost scuttled the trade legislation, known as fast track, which would clear the way for a sweeping Pacific trade agreement that is a top priority of the president’s second term.

...