As an aircraft approaches the speed of sound, an effect known as wave drag starts to appear. This happens because the air which would normally follow a streamline around the aircraft no longer has time to "know" about the approaching object and simply hits it directly. This results in greatly increased drag. Research into the nature of this effect led to the conclusion that it was reduced by having the profile of the aircraft change as slowly as possible, what we today refer to as fineness ratio, leading to long highly-tapered profiles.
This effect was known about in the 1930s, but due to the fairly low speeds most aircraft were capable of, it was largely of academic interest. Large engines at the front of the aircraft made it difficult to obtain a reasonable fineness ratio, and although wings could be made thin and broad, doing so made them considerably less strong. The British Supermarine Spitfire deliberately used as thin a wing as possible for lower high-speed drag, but later paid a high price for it in a number of aerodynamic problems such as control reversal. German design instead opted for thicker wings, accepting the drag for greater strength and increased internal space for landing gear, fuel and weapons.
A practical solution had already been offered however, as long ago as 1936 by German engineers at a public aeronautics meeting in Italy. In their presentation they noted that the wing "thickness" for these calculations was measured along the direction of the airflow, as opposed to along the line of the chord. A thick wing could be made "effectively thinner" by rotating it at an angle to the airflow, sweeping it back. With planes starting to approach only 400km/h at the time, the presentation was soon forgotten.
Things started changing dramatically with the introduction of jets in the later half of World War II. The first German high-speed designs, the jet powered Messerschmitt Me 262 and rocket powered Messerschmitt Me 163, suffered from compressibility effects that made them very difficult to control at high speeds. In addition the speeds put them right in the wave drag regime, and anything that could reduce it would increase the performance of their aircraft, notably the notoriously short flight times measured in minutes.
The result was a crash program to introduce new swept wing designs, both for fighters as well as bombers. A prototype test aircraft, the Messerschmitt P.1101, was built in order to research the tradeoffs of the design and develop general rules about what angle of sweep to use. None of the designs were ready for use by the time the war ended, but the P.1101 was captured by US forces and returned to the United States, where two additional copies with US built engines carried on the research as the Bell X-5.
The introduction of the German swept-wing research to aeronautics caused a minor revolution, and almost all design efforts immediately underwent modifications in order to incorporate a swept-wing. A particularly interesting victim was the cancellation of the Miles M-52, a straight-wing design for an attempt on the speed of sound. When the swept-wing design came to light the project was cancelled, as it was thought it would have too much drag to break the sound barrier, but soon after the US nevertheless did just that with the Bell X-1. The results of all of these design efforts started reaching production by the 1950s, when practically every fighter used a swept wing. It was at this point that another problem discovered by the Germans came to light.
When a swept-wing travels at high speed, the airflow has little time to react and simply flows over the wing. However at lower speeds there is more time for motion and a strong streamline, and with the front of the wing angled, some of the air is pushed to the side towards the wing tip. At the wing root, by the fuselage, this has little noticeable effect, but as you move towards the tip the airflow is pushed sidewise not only by the wing, but the sidewise moving air beside it. By the time you reach the tip the airflow is moving along the wing instead of over it, a problem known as spanwise flow.
The problem with spanwise flow is that the lift of the wing is generated by the airflow over it from front to rear. As an increasing amount travels spanwise, the amount flowing front to rear is reduced, leading to a loss of lift. Normally this is not much of a problem, but as the plane slows for landing the tips can actually drop below the stall point even at speeds where stalls should not occur. When this happens the tip stalls, and since the tip is swept to the rear, the net lift moves forward. This causes the plane to pitch up, leading to more of the wing stalling, leading to more pitch up, and so on. This problem came to become known as Sabre dance in reference to the number of North American F-86 Sabres that crashed on landing as a result.
The solution to this problem took on many forms. One was the addition of a strip of metal known as a wing fence on the upper surface of the wing to redirect the flow to the rear (see the MiG-15 as an example), another closely related design was to add a dogtooth notch to the leading edge (Avro Arrow). Other designs took a more radical approach, including the XF-91 Thunderceptor's wing that grew thicker towards the tip to provide more lift there, and the British-favoured compound sweep or scimitar wing that reduced the sweep along the span, used on their V Bombers.
Modern solutions to the problem no longer require "custom" designs such as these, but are taken as a whole with the need for shorter takeoff and landing than the early large jets. The addition of leading edge slats and large compound flaps to the wings have largely resolved the issue. On fighter designs, the addition of leading edge extensions, included for high manoeuverability, also serve to add lift during landing and reduce the problem.
The swept-wing also has several more mundane problems. One is that for any given length of wing, the actual span from tip-to-tip is shorter than the same wing that isn't swept. Low speed drag is strongly correlated with the aspect ratio, the span compared to chord, so a swept wing always has more drag at lower speeds. Another concern in the torque generated at the fuselage, as much of the wing's lift lies behind where the root connects to the plane. Finally, while is is fairly easy to run the main spars of the wing right through the fuselage in a straight wing design to use a single continuous piece of metal, this is not possible on the swept wing because the spars will meet at an angle.