LONDON — Abdul Rahman Haroun, a Sudanese refugee who braved speeding trains to walk 31 miles through the Channel Tunnel last summer, was sentenced on Wednesday after pleading guilty to the charge in Britain of “obstructing a railway carriage or engine,” a 19th-century law that carries a maximum penalty of two years in prison.

He was sentenced to nine months in prison but was allowed to walk free because of the time he had already spent incarcerated.

Mr. Haroun was scheduled to stand trial on Wednesday after pleading not guilty to the charge at a preliminary hearing on Aug. 24. His lawyer was not available for comment on why the plea was changed.

Mr. Haroun’s extraordinary effort to come to Britain made him a potent emblem of the desperation of huge numbers of migrants seeking refuge in Europe, and in January, he was granted asylum after several months in jail.