MOSCOW — Aleksei A. Navalny returned to his home country Sunday, five months after a near-fatal nerve-agent attack, and was arrested at the border, a show of fearlessness by Russia’s most prominent opposition leader and of anxiety by President Vladimir V. Putin.

In hours of live-streamed drama that played out in Berlin, in the air and at two Moscow airports, Mr. Navalny careened headlong into near-certain detention after deciding to leave the relative safety of Germany, where he had been recovering from last summer’s poisoning.

Hundreds of people braved the bitter cold outside Moscow’s Vnukovo Airport to greet Mr. Navalny, but the low-cost Russian airline he was flying was diverted just before landing to a different Moscow airport. There, at passport control, Mr. Navalny was confronted by uniformed policemen in black masks.

He embraced his wife, Yulia Navalnaya, before being led away.

“I am not afraid,” Mr. Navalny told reporters just before he was detained, standing in front of a neon sign at the airport that portrayed the Kremlin. “I know that I am in the right and that all the criminal cases against me are fabricated.”

Mr. Navalny’s arrest had been expected, but the day offered some of the most dramatic images of recent years underlining both Russia’s rising domestic discontent and the Kremlin’s jitters over it.

Scores of riot police officers in camouflage uniforms and shiny black helmets swarmed the arrival halls of Vnukovo, detaining dozens. Other officers, some in plainclothes, swooped in on some of Mr. Navalny’s top associates as they dined at an airport cafe and led them away.