Today, commercial aircraft cockpit is manned by 2 pilots, previously it was 3 to 5. Is safety compromised in any way?
No aircraft ever had more than two pilots (on duty at the same time).
The additional flight crew members were flight engineer, navigator and radio operator.
- Dedicated radio operators were only needed in the early days when the radio was primitive and required some care and experience to tune properly. As it improved, operating radio was merged into navigator or flight engineer job and eventually became simple enough for pilots to do themselves.
- Navigators were used on long-distance flights especially over water. They kept track of the progress on the map and corrected the position using celestial navigation and some landmarks where available. With advent of inertial navigation systems and long range radio this simplified enough that dedicated crew member was not needed any more.
- Flight engineer was most common and remained longest. Engines had many gauges that needed monitoring and controls that had to be correctly set to start them and adjusted to keep them running efficiently. And while turbine engines are simpler to manage than piston ones, the addition of more electric and hydraulic system meant that there was still a lot to set up and monitor. But now this job is done by a computer that monitors all the parameters and displays specific messages when something fails including instructions what needs to be checked and done for each problem.
In the meantime, the improvements in autoflight systems freed more time for the pilots in which they can now handle, with help of the electronics, the tasks that before needed a dedicated crew member.
Due to these technological advances allowing for the removal of these crew members, overall flight safety has not been compromised. It is likely that safety has actually improved by reducing the probability of human error.
Back before satellite navigation, affordable inertial navigation systems and small digital computers people had to do the tasks which are now automated. Navigation on long overwater flights was done by sextant, engines were managed by a flight engineer, etc. More people were needed because the jobs could not be done in any other way
Nowadays computers very efficiently handle many of the tedious and complex tasks, so there simply is not a need for additional cockpit crew. As for whether safety is compromised I would suggest you look at the accident rate over time as it's much lower than it used to be. As for how much of that is due to better automation in the cockpit I cannot say, but it certainly has not increased the accident rate.
Your question seems to imply that having an extra hand on deck would help prevent an accident, which is not always true. Firstly, let's make a historical note that you're far from the first one to ask this question. When the DC-9-80 was being certified there was a heated debate between pilot unions and manufacturers over whether the two pilot crew was sufficiently safe, and a presidential commission tasked to investigate in 1981 concluded that:
The safety record of aircraft flown by crews of two is at least as good as the safety record of aircraft flown by crews of three. In our judgment, the presence of a third crew member in the DC-9-80 would not improve the ability of the crew to operate the aircraft safely in the air traffic environment. Therefore, safety-related improvements must come from measures other than enlarging the size of the flight crew.
The other answers have focused on decreased necessity of an extra crew member for navigation, engine tuning, and radio usage. I'd like to explain in the rest of my answer why having an extra crew member doesn't always prevent mistakes from a crew resource management (CRM) perspective. Occasionally in practice the extra crew member made the plane less safe.
CRM developed after some major cases where the flight engineer was ignored by the pilots and a crash resulted. In these cases the flight engineer certainly didn't prevent the accident. After all, when EAL Flight 401 descended too close to the ground the flight engineer wasn't even in the cockpit to monitor the low altitude alarm that sounded from his station. In my opinion the flight engineer's presence potentially makes it easier for the pilot to ignore warning signs that are the flight engineer's responsibility.
UA 173, one of the pivotal crashes for CRM, happened during approach when a problem with landing gear extension left the landing gear down and locked, but damaged the landing gear sensor assembly so that the landing gear indicator light did not come on. The pilots focused on this issue, and ignored the rapidly dwindling fuel supply. The flight engineer gave repeated hints about the fuel problem but the pilot ignored him. The NTSB said the pilot failed to monitor the fuel supply and did not take the flight engineer's comments seriously, and the flight engineer was not assertive enough.
The infamous Tenerife airport disaster happened when a pilot mistakenly thought he had takeoff clearance in low visibility and collided with a Pan-Am 747 that was still taxiing. The flight engineer of the taking-off plane had asked "Is he not clear, that Pan-American?" to which the pilot simply responded "Oh yes". The breakdown in CRM prevented the flight engineer from stopping the crash.
Accidents in which a flight engineer caused or failed to prevent an accident have greatly been mitigated by the improvements in CRM, but they still happen. In 2011, RusAir Flight 9605 crashed after the navigator had been giving mistaken directions and was even intoxicated, but the pilot did not question his guidance. Once again, the flight engineer may have made it easier for the pilot to ignore warning signs due to a breakdown in effective CRM. This was a similar situation to the 1996 Charkhi Dadri mid-air collision that TomMcW pointed out.
The President's Task Force on Aircraft Crew Complement similarly concluded that:
there is no advantage to any particular crew size in relation to safe and effective cockpit resource management. We also interpret incident, accident, and relevant research data to indicate that it is more difficult to achieve effective crew integration with larger crews. Distractions... should be dealt with by instituting more effective operational controls rather than by using a larger operating crew.
In summary, having an extra set of hands in the cockpit only helps safety when the crew is communicating effectively and using proper CRM. Quite a few flight engineers have failed to prevent or have even caused a crash.