President Obama and Senator Robert Menendez traded sharp words on Thursday over whether Congress should vote to impose new sanctions on Iran while the administration is negotiating with Tehran about its nuclear program, according to two people who witnessed the exchange.

In the course of the argument, which was described as tense but generally respectful, Mr. Obama vowed to veto legislation being drafted by Mr. Menendez, Democrat of New Jersey, and Senator Mark Kirk, Republican of Illinois, that would trigger sanctions after multiparty talks are set to end this summer.

Their face-off occurred behind closed doors at the Hilton in Baltimore, where the two-day Senate Democratic Issues Conference was taking place. The president spoke to the senators for nearly two hours, and several people said he was well received by members of his party as he vowed to remain on the political offensive during the final two years of his presidency.

His exchange with Mr. Menendez occurred near the end of a question-and-answer session after Senator Angus King of Maine — an independent who caucuses with the Democrats — asked for an update to the nuclear talks.