WASHINGTON — Senator Joe Manchin III so craved a pro-gun-rights Republican as a partner for a bill to expand background checks on gun buyers that he took to buttonholing senators on the in-house subway that ferries them from their offices to the Capitol, making his pitch while his colleagues were trapped with him in the tiny car.

Repeatedly rebuffed, Mr. Manchin, a conservative West Virginia Democrat, decided to call on his friend Senator Patrick J. Toomey, the Pennsylvania Republican known almost exclusively for his conservative fiscal positions. On a recent Amtrak trip from New York to Washington where they happened to intersect, Mr. Toomey agreed to listen.

On Wednesday the two gun owners, long favorites of the National Rifle Association, came together in a last-ditch effort on a background check compromise that opened the door to a rare Congressional consideration of gun law changes, beginning Thursday. While their agreement ensures only that the measure will reach the Senate floor for debate, it rescued gun law changes sought by President Obama and gun control groups from an early defeat.

Lawmakers who represent neighboring states, allies on energy issues and temperamentally aligned, Mr. Manchin and Mr. Toomey announced they had gingerly put together a bipartisan deal that would expand background checks to cover unlicensed dealers at gun shows as well as all online sales.