Hillary Clinton holds a small lead over Donald J. Trump nationally, according to a poll released on Wednesday that shows United States voters sharply divided along gender and party lines.

The poll, by Quinnipiac University, found that 45 percent of voters supported Mrs. Clinton, while 41 percent backed Mr. Trump. When adding candidates from other parties, such as Gary Johnson, the Libertarian nominee, and Jill Stein of the Green Party, the race becomes a virtual tie, with Mrs. Clinton leading Mr. Trump by just two percentage points.

The survey had a margin of error of plus or minus three percentage points.

The results suggest that Republicans and Democrats are ready to line up behind their likely standard-bearers, with 86 percent of Republicans supporting Mr. Trump and 90 percent of Democrats backing Mrs. Clinton, who is still working to defeat her opponent in the primaries, Senator Bernie Sanders of Vermont.

Like in many polls, Mr. Sanders performed better than Mrs. Clinton against Mr. Trump in a hypothetical matchup, leading him by nine percentage points.