WASHINGTON — One moment he boasts about taking out America’s No. 1 enemy, and the next he vows to bring home troops from an unpopular war. For President Obama, the days leading up to his re-election kickoff have been spent straddling the precarious line between hawk and dove, and possibly redefining his party for years to come.

For four decades, Democrats have been confounded by a deeply ingrained soft-on-security image that has hurt them at the ballot box. But in a country now tired of war yet still seeking to project strength, Mr. Obama is trying to reposition his party on national security, much as Bill Clinton did on economic and domestic policy in the 1990s, triangulating between two poles.

The blend, captured by an unannounced trip to Afghanistan on Tuesday that ended in a nationally televised address, has frustrated critics on both left and right. Many in his party’s liberal base have grown disenchanted with Mr. Obama for tripling troop levels in Afghanistan, carrying over many of President George W. Bush’s counterterrorism policies and in some ways even expanding them. Many conservatives, on the other hand, argue that behind the raid that killed Osama bin Laden lies a fundamentally weak approach to rivals and rogue states like Iran, North Korea and Russia.

If it seems to some like the doctrine of having it both ways, it has scored well with a broad cross-section of the country, as measured by polls and focus groups. And Mr. Obama’s advisers have made clear in recent days that they believe he can play offense on national security as no other Democratic presidential candidate has since the Vietnam War.