WASHINGTON—Testimony of a White House national security official turned combative Tuesday as Democrats accused Republicans of trying to unmask the whistleblower who sparked the impeachment inquiry of President Trump, while the GOP lawmakers argued theirs was a legitimate line of questioning.

The appearance by Army Lt. Col. Alexander Vindman, a White House Ukraine expert who testified that he expressed alarm at a U.S. pressure campaign on Ukraine’s president over the summer, spurred Mr. Trump and his allies to attack his background...