Daniil Medvedev surged into the top five in the world rankings this month, playing excellent tennis with an unflappable calm he has often lacked in his career.

As he made a run of three consecutive finals, he said he was happy “I didn’t get crazy, even for one second, on the court.”

Then came Friday night at the United States Open.

In the first set of his third-round match against Feliciano López, Medvedev, 23, incensed the crowd at Louis Armstrong Stadium by angrily snatching a towel out of the hands of a ball man and tossing it on the court, for which he earned a code violation for unsportsmanlike conduct.

To show what he thought of the fans’ disapproval, Medvedev held up his middle finger next to his head, out of view of the officials, but in sight of much of the crowd. Then the gesture was shown on video screens inside the stadium.