The foundational rule, as stated by the Shulchan Arukh (Orach Chayim 55:9), is that a boy remains a minor until he has brought two hairs after completing thirteen years and one day, with a leap year counting as thirteen months — meaning the full calendar must be traversed before bar mitzvah status attaches.
The Tur (Orach Chayim 55) establishes that all ten members of a minyan must be free adults who have brought two hairs, so the precise moment a boy crosses into majority is directly determinative of whether he may be counted.
The critical complication for a Rosh Chodesh birthday is addressed directly by Shulchan Arukh HaRav (Orach Chayim 55), which rules that a boy born on the first day of a two-day Rosh Chodesh — which is in fact the thirtieth day of the prior month — does not become bar mitzvah until Rosh Chodesh of the thirteenth year, because thirteen full years day-to-day have not elapsed until twenty-nine complete days of the prior month have passed; the fact that months and years are counted from the second day of Rosh Chodesh, which is the primary day, does not accelerate the completion of the full thirteen years.
The Arukh HaShulchan (Orach Chayim 55) adds that no distinction is drawn based on whether the structure of Rosh Chodesh at birth and at bar mitzvah is identical or different — including cases where a month that was one day of Rosh Chodesh at birth becomes two days at bar mitzvah, or vice versa, as with Kislev and Tevet — and that in all such cases the boy becomes bar mitzvah on Rosh Chodesh.
The Mishnah Berurah (55:42) clarifies that even a boy born at the very end of the day of Rosh Hashanah becomes bar mitzvah at the start of the night beginning his fourteenth year, reinforcing that the count runs precisely from the moment of birth, and that any uncertainty at twilight is treated stringently in matters of Torah law.