In the past people used to measure the length of a year according to the moon 28-days cycle but this obviously left a few days out, so I was wondering which civilization first realized this and fixed the problem? The Romans?
The Sumerian and Egyptian and old Roman calendars were practical ones - they simply added one or two days to a year when it was needed.
The Julian calendar was theoretical one - it was the first known calendar that set the months and days in all years beforehand. So a common man could and can know beforehand when the spring comes.
But even Julian or later Gregorian calendars don't coordinate sun and moon cycles.
As for beforehand moon/sun coordination, it was Mayan calendar that counted for all. It was very unpractical and complicated though. But precision was not bad - their predicted end of calendar had error only 3 days for 1000 years - very well for coordination of 3 independent cycles
Short and quick answer: definitely the Romans were NOT the first. Calendar of ancient Egyptians was solar, and Sumerian one - lunisolar, both of them fit your description, although the issue which of them is older is open, and in fact is a discussion of interpreting archeological materials. Hence it would be also impossible to provide any definitive, precise date for calendar development. Still, origin of both Egyptian and Sumerian one may be roughly dated to some time around 3000-2500 BC.