Close a popup with an OP call
One way to solve it would be by moving the cursor out of the panel temporarily, like so:
def close_panel(event):
    x, y = event.mouse_x, event.mouse_y
    bpy.context.window.cursor_warp(10, 10)

    move_back = lambda: bpy.context.window.cursor_warp(x, y)
    bpy.app.timers.register(move_back, first_interval=0.001)

How this works is: first, we grab the X and Y values of the current mouse position, because in the next line the event is updated, and we lose the original coordinates.
Next, we move the cursor way over to the bottom left corner of the screen (not 0, 0 though because that doesn't close the panel for some reason).
Then, we prepare a function which moves the cursor back to where it was originally.
And finally, we use bpy.app.timers to delay starting our function by 1 millisecond, to give Blender time to realize the cursor is no longer on the panel, and close it.