LONDON—Prime Minister Theresa May, who spent six years in charge of the U.K.’s interior ministry, is facing her first major test handling a security crisis since becoming the country’s leader following the Brexit vote.

Days before she is set to formally start Britain’s exit from the European Union, Mrs. May will have to juggle the fallout of the deadly attack Wednesday at the heart of the government as she guides the nation through a historic transformation.

...