WASHINGTON  President-elect Barack Obama has decided to keep Defense Secretary Robert M. Gates in his post, a show of bipartisan continuity in a time of war that will be the first time a Pentagon chief has been carried over from a president of a different party, Democrats close to the transition said Tuesday.

Mr. Obama’s advisers were nearing a formal agreement with Mr. Gates to stay on for perhaps a year, the Democrats said, and they expected to announce the decision as early as next week, along with other choices for the national security team. The two sides have been working out details on how Mr. Gates would wield authority in a new administration.

The move will give the new president a defense secretary with support on both sides of the aisle in Congress, as well as experience with foreign leaders around the world and respect among the senior military officer corps. But two years after President Bush picked him to lead the armed forces, Mr. Gates will now have to pivot from serving the commander in chief who started the Iraq war to serving one who has promised to end it.

In deciding to ask Mr. Gates to stay, Mr. Obama put aside concerns that he would send a jarring signal after a political campaign in which he made opposition to the war his signature issue in the early days. Some Democrats who have advised his campaign quietly complained that he was undercutting his own message and risked alienating war critics who formed his initial base of support, especially after tapping his primary rival, Senator Hillary Rodham Clinton, for secretary of state.