Stock sale across the end of the year

I sold some stock on the last day of December 2023. Transaction date is in December. Settlement date is in the beginning of January 2024. Do I realize capital gain/loss in 2023 or 2024?