LONDON — Queen Elizabeth II formally opened Parliament on Monday and promptly found herself in the thick of Britain’s roiling Brexit drama, setting out a legislative agenda for Prime Minister Boris Johnson’s government that began with his vow to leave the European Union by the end of this month.

In a ceremony suffused with age-old pageantry but overshadowed by the frantic search for a Brexit deal, the queen declared that the Johnson government “intends to work toward a new partnership with the European Union, based on free trade and friendly cooperation.”

In fact, Mr. Johnson’s hopes for an agreement on Brexit appeared to be on a knife edge, as British and European negotiators in Brussels wrangled in the waning days before Oct. 31 over the vexing question of how to handle trade with Northern Ireland after Britain leaves the economic bloc.

The uncertainty over whether Mr. Johnson will strike a deal in time, the intense maneuvering that is certain to follow his success or failure and the possibility that Mr. Johnson himself may be pushed from office in the coming month made this one of the most unusual queen’s speeches of the modern era.