For the last couple of years, Special Counsel Robert Mueller has been President Donald Trump’s bad dream. But now, he has a Pelosi problem, as in Speaker of the House Nancy Pelosi. She and her gavel will be Mr. Trump’s worst nightmare.

Mr. Trump got a taste of the Pelosi style in their recent Oval Office encounter. He was expecting the San Francisco elitist. He got the Baltimore street fighter.

Ms. Pelosi was born and lived her youth in Baltimore. Politics was a family affair. Her father, Thomas D’Alesandro Jr. — known simply as “Tommy” — was an old style city mayor where patronage propped up the government and building a precinct organization was the work of God. Her mother ran the precincts and distributed the favors with an iron fist. Her brother and mentor, still known at age 89 as “Young Tommy,” was elected mayor in 1967 when mayors were influenced more by Jack Kennedy than by Richard Daley.

But their era collided with public anger over Vietnam and opposition to civil rights demands. Residents of troubled urban centers could not understand why their kids wore long hair and children from distant neighborhoods would now be bused to their schools. In Maryland, the Democratic candidate for governor campaigned on a slogan of “your home is your castle” and won the nomination. Democrats, offended by the slogan, bolted their party and elected Spiro Agnew — a Republican. When the City Council resisted passage of a municipal civil rights bill, Young Tommy enlisted Martin Luther King Jr.’s help and cut a few deals to round up disparate opponents until they had a bare majority. Like other cities, Baltimore experienced riots. Young Tommy did not escape the turmoil. He did not seek reelection.

Ms. Pelosi, 78, lived through all this. She learned how to deal with back room politicians, how to organize a precinct and how to entice legislators to unify behind controversial issues. After college, she interned in a congressional office when the two most powerful politicians were Speaker Sam Rayburn and Senate Majority Leader Lyndon Johnson. This is what shaped her political career before she moved to San Francisco and was elected to Congress. She learned early how to stand up to bullies.

Those of us who grew up with Nancy Pelosi and stayed in touch through her career were not surprised that, when pushed around by the president, she unleashed the combined force of a backroom brawler from Baltimore and a smart, classy adversary from San Francisco — handing the president a verbal whacking and then strolling out of the Oval Office with the poise of a fashion model wearing a stylish orange coat and designer sunglasses.

The differences between Speaker Pelosi and President Trump are stark.

Ms. Pelosi is a formidable strategist, plotting the successful slaughter of Republican congressional candidates by instructing Democratic candidates to ignore Mr. Trump and focus on issues facing their local constituencies. Meanwhile, Mr. Trump put his strategic eggs in the basket of feeding his base with phony tirades about walls, caravans and mythical Mexican rapists.

Ms. Pelosi knows the difference between campaigning and governing. Mr. Trump can’t get out of campaign mode and has yet to start actually governing. Ms. Pelosi has been organizing committees, setting priorities and launching an aggressive legislative program that she articulated in her recent acceptance speech.

Mr. Pelosi is smarter than President Trump — a lot smarter. She knows the difference between the Balkans and the Baltics and has a working knowledge of the historic animosity between Armenians and Turks, Jews and Palestinians, Russians and new Eastern European countries formerly part of the Soviet Union. She stands in contrast to a president who thinks the New Deal is a card game, Shiites and Sunnis are Middle East dishes and Vladimir Putin is our friend.

Ms. Pelosi reads. She assembles information from books, thoughtful essays and briefings from experts. She absorbs and retains the information and deploys it with thought and common sense. Mr. Trump watches Fox News, listens to Rush Limbaugh, and forms his policies from locker room talk with his golf buddies.

Ms. Pelosi deals with facts. Mr. Trump lies multiple times a day and deals in conspiracy theories — the birther issue and his recent bizarre revisionism of Russian history that would embarrass a high school dropout, just to name two.

Ms. Pelosi is a masterful legislator well schooled on parliamentary intricacies and the art of massaging legislation to corral wavering members. Even with a majority in Congress, Mr. Trump was unable to repeal Obamacare or build his cherished wall. Ms. Pelosi’s skills were sharpened by familiarity with politicians from different cultures and explain why she continually holds together a remarkably diverse Democratic caucus.

Ms. Pelosi has profound respect for the office she holds. Mr. Trump seems oblivious to his. She also respects the great national institutions that Mr. Trump dismisses with daily tweet storms. She believes that a free press and a loyal opposition are valued assets, that the judiciary should remain independent and that international treaties that have been the core of the U.S. rise as the most trusted global leader in history should be honored.

Ms. Pelosi will not hesitate to exercise the U.S. House of Representatives’ constitutional responsibility to oversee the executive branch. She has authorized appropriate committees to investigate the disruptive management of departments and to conduct congressional scrutiny of the president’s behavior already under multiple investigations.

Ms. Pelosi will not be intimidated — not by a Republican attack machine with its menacing media cohorts who spent the last 20 years demonizing her to no avail, and not by a narcissistic presidential bully.

President Trump brags that he relies on his brain and his guts to make decisions. Right now, both should be telling him: Don’t mess with Speaker Pelosi.

Theodore G. Venetoulis, a businessman and former Baltimore County executive, is author of “The House Shall Choose,” a book about the two times Congress has selected the president. His email is ted.venetoulis@gmail.com.