House Speaker Nancy Pelosi (D-Calif.) arrives for a press conference on Capitol Hill on Jan. 24. (Bill O'Leary/The Washington Post)

As House Speaker Nancy Pelosi waged her high-profile shutdown standoff with President Trump, she was working behind the scenes on an even more delicate task — keeping her big, restless and inexperienced caucus on the same page.

During her first month leading the new Democratic majority, Pelosi (D-Calif.) has doled out a record number of subcommittee gavels to new members, while encouraging others to take leading roles on the political front lines. Meanwhile, she firmed up support among old stalwarts with choice committee assignments while moving quickly to calm jittery freshmen.

Together, according to interviews with more than a dozen Democratic lawmakers and aides, the fight to end the 35-day partial government shutdown and a meticulous effort to distribute power among the party’s various ideological and generational factions has kept internal peace for the time being as Democrats eye the rest of their governing agenda.

“She fundamentally believes new people enrich democracy and bring new ideas, but she also values people’s experience here,” Rep. Ro Khanna (D-Calif.) said of Pelosi. “I think that it’s a very delicate balance.”

What has so far emerged is a mutual respect between party factions that has belied predictions of the kind of ideological strife that bedeviled Republicans during their previous eight-year House majority.

In particular, a predicted “herbal tea party” of young far-left Democrats have instead emerged as some of Pelosi’s loudest allies and trusted messengers for the party leadership. If anything, a larger group of moderate Democrats who unseated Republicans in Trump-voting districts have proved to be the bigger management challenge for Pelosi.

Late last month, with the shutdown still in full swing, Rep. Alexandria Ocasio-Cortez (D-N.Y.) — the unquestioned left-wing star of the freshman class — rose behind closed doors in a caucus meeting to describe how a group of freshmen women had staged a well-publicized march to find Senate Majority Leader Mitch McConnell (R-Ky.). With some moderate members representing Trump districts quietly questioning the party’s no-border-wall strategy, she urged her colleagues to keep their fire trained on McConnell — not on fellow Democrats.

Hours later, Pelosi’s office sent out a release echoing that view and promoting the social media hashtag #WheresMitch that the freshmen had publicized.

In an interview, Ocasio-Cortez (D-N.Y.) compared the 235-member Democratic caucus to a soccer or football team.

“Whatever sport, you have some folks who are defenders. You have some folks whose job is to go past the norm and go past that middle line to bring the ball to the end. And I think that we can work in tandem — we don’t have to all have the same position on everything in order to be a party,” Ocasio-Cortez said.

That attitude is music to the ears of Democratic moderates — the “majority makers” — who fear that extremism will turn off crucial swing voters.

“The press, with all due respect, is trying to set it up as a battle between left and right — we’re not biting,” said Rep. Kurt Schrader (D-Ore.), a leader of the moderate Blue Dog Coalition. “I have nothing against the [Ocasio-Cortezes] of the world. That’s fine. They represent their district. Let me represent mine. So far, that seems to be the case.”

Caught in the middle is Pelosi, who appears to have moved firmly past a post-election struggle to regain the speaker’s gavel and recently finished handing out committee assignments and some other political ducats. That process played out over the course of several months, involving scores of private meetings with lawmakers.

No first-term lawmaker won a slot on the most exclusive committees — panels such as Ways and Means, Energy and Commerce, and Appropriations that are considered the choicest assignments. That decision, aides say, was a gesture of respect to House veterans who have worked to raise money and win reelection to earn those slots.

But some freshmen won posts on high-profile panels such as Oversight and Judiciary that are likely to be in the media spotlight as Democrats train their attention on the Trump administration.

“I think I landed exactly where I needed to land,” said Rep. Rashida Tlaib (D-Mich.), who sits on the Financial Services and Oversight panels, crediting Pelosi with giving her a platform to highlight working-class issues. “Everything she said she did, and I think that was a great start for us to be able to build this really trusting working relationship with her.”

In other committees, 18 freshmen won subcommittee gavels — a record high for a Democratic majority — giving the newcomers small but politically valuable pieces of legislative turf.

Rep. Andy Kim (D-N.J.), who narrowly prevailed in a district Trump won in 2016 by six percentage points, was named chairman of the Small Business subcommittee on economic growth, tax and capital access. In an interview, he expressed gratitude and called the post “a place where I can do a lot of good for my district” but expressed some surprise at his selection.

“I’ll be honest with you. . . . I don’t know how it is I got it,” said Kim, who has a background in national security policy.

According to a Democratic aide familiar with the process, who spoke on the condition of anonymity to discuss the conversations freely, Pelosi privately told some freshmen that showing early interest in lower-profile committees could yield a subcommittee gavel.

A few Pelosi critics appeared to pay for their opposition. Rep. Kathleen Rice (D-N.Y.), who voted against Pelosi last month, was denied a slot she had sought on the Judiciary Committee, and Rep. Seth Moulton (D-Mass.), who led opposition to Pelosi for months but ultimately voted for her, did not win a slot on the Transportation and Infrastructure panel or the chairmanship of an Armed Services subcommittee.

But those in, exception rather than the rule: Others who voted against Pelosi won coveted posts, such as Rep. Mikie Sherrill (D-N.J.), who was named chairman of the Science, Space and Technology subcommittee on oversight.

Rep. Mark Meadows (R-N.C.), the House Freedom Caucus chairman who was the target of multiple GOP leadership retaliation attempts, said that Pelosi was handling her caucus in the only reasonable way in the modern age: “not a whole lot of stick, but a whole lot of carrot.”

“We’re in a different era right now: Social media has made a more level playing field,” he said. Party leaders punishing rank-and-file members “can go viral in a few minutes, and it normally has the opposite effect” of what leaders intend.

Ocasio-Cortez, for instance, has 600,000 more Twitter followers and about 1.8 million more Instagram followers than Pelosi — giving her an extensive and unfiltered media reach that outspoken liberals of other eras never had.

And there is little doubt that the true tests of party unity are still to come: The hard-left members have already warned they will not vote for increases in some border security or immigration enforcement funding, they have pressed for more aggressive action to address climate change, and even more divisive ideas could come onto the House radar in the coming months — such as proposals for universal health care.

But to many Democrats surveyed, the first month — thanks both to Trump and Pelosi — has set an encouraging tone for the next two years. To some top leaders, that reflects a shared sensibility in the party versus Republicans.

“I think we’ve shown over a long period of time that the Democratic Party has significantly greater unity within its ranks,” House Majority Leader Steny H. Hoyer (D-Md.) told reporters this week. “Unlike our Republican colleagues, which have continually displayed an ongoing and immobilizing disunity within their caucus.”

Others, however, see a skilled hand at the tiller. Ocasio-Cortez, for instance, credited Pelosi for listening to the incoming liberals and understanding their agenda.

“She respects intellectual and policy dissent but not tactical division,” Khanna said. “You can think you have a better foreign policy vision, perhaps — an economic vision, social justice vision, racial justice vision. But do you have a better aptitude to be speaker of the House?”