WASHINGTON  The Senate on Wednesday turned aside the latest effort by gun advocates to expand the rights of gun owners, narrowly voting down a provision that would have allowed gun owners with valid permits from one state to carry concealed weapons in other states.

A group comprising mostly Republicans, along with some influential Democrats, had tried to attach the gun amendment to the annual military authorization bill, a must-pass piece of legislation. But the provision got only 58 votes, two short of the 60 needed under Senate rules.

Two Republicans, Senators Richard G. Lugar of Indiana and George V. Voinovich of Ohio, joined with 35 Democrats and 2 independents to reject the amendment, which was bitterly opposed by a number of big-city mayors, including Michael R. Bloomberg of New York.

The debate forced senators to wrestle with issues of states rights, sometimes in ways that seemed to clash with the general philosophies of their parties. Many Republicans, who typically favor limiting the ability of the federal government to dictate to states on social issues, voted in this case to limit the ability of states to insist on their own rules for concealed weapons carried by people from other states.