The grounds and building of any embassy are considered part of the country owning the embassy. In other words, the American embassy in Beijing is considered to be American soil for so long as it is used as an embassy. In the same way, foreign embassies in the United States are considered part of the foreign country even though they are located in Washington, D.C. Also, many countries have what amount to embassy branch offices in major cities, called consulates. Again, these are considered part of the sponsoring country.
If a person enters an embassy, that person is considered a guest of country whose embassy he has entered. The embassy can tell him to leave if he is not welcome in the embassy -- just getting in does not necessarily mean he is allowed to stay -- but so long as he is in the embassy, the host country cannot send anyone in to take him out. If the person is someone who the embassy country wants to protect, they can grant the person "asylum." This means that he is free to stay in the embassy.
By international convention that has dated back literally for centuries, an attempt to intrude on one embassy is an attempt to violate every embassy. The entire diplomatic community will protest as a group. The leader of the protest is always the ambassador who has the longest tenure in the country. This has led to some fascinating cases, because the United States is very protective of its embassies, but tends to use very short-term ambassadors. So when a host country breaches the standards of diplomacy by, for example, having local police get heavy with American embassy personnel, the American ambassador does not lodge a complaint with the host government, because he rarely has sufficient time in country. Commonly, the duty of protesting goes to the country which has tended to use almost permanent ambassadors, the People's Republic of China. Notably, the Communist Chinese have a very distinguished record that even when the United States for decades refused to recognize the Chinese as the legitimate rulers of their own country, when there was trouble in a foreign country and the United States needed diplomatic courtesies, the Chinese were outstanding in performing this duty.