The Gemara says:
תָּנוּ רַבָּנַן: הָיָה עוֹמֵד בִּתְפִלָּה וּמַיִם שׁוֹתְתִין עַל בִּרְכָּיו — פּוֹסֵק עַד שֶׁיִּכְלוּ הַמַּיִם וְחוֹזֵר וּמִתְפַּלֵּל. לְהֵיכָן חוֹזֵר? רַב חִסְדָּא וְרַב הַמְנוּנָא, חַד אָמַר חוֹזֵר לָרֹאשׁ, וְחַד אָמַר: לְמָקוֹם שֶׁפָּסַק
The Sages taught in a baraita: One who was standing in prayer when, for some reason, urine is flowing on his knees, he must interrupt his prayer until the urine ceases, and then resume praying. The Gemara, asks: To where in the prayer does he return when he resumes his prayer? Rav Chisda and Rav Hamnuna disagreed; one said: He must return to the beginning of the prayer, and the other said: He must return to the point where he stopped. [Berachot 22b]
The last opinion is codified in Shulchan Arukh, Orach Chayim 78:1.
I would conclude that it is best to go to the bathroom BEFORE starting the prayer; but if you didn't, do as it says above.
Yevamot 62b notes that Rav Huna’s speeches were so drawn out that Rav Sheshet became impotent because he waited too long before relieving himself. I hope we don't have to go that far today.